package dataqueue;
import java.io.IOException;
import com.ibm.as400.access.AS400;
import
com.ibm.as400.access.AS400SecurityException;
import com.ibm.as400.access.DataQueue;
import
com.ibm.as400.access.ErrorCompletingRequestException;
import com.ibm.as400.access.IllegalObjectTypeException;
import
com.ibm.as400.access.ObjectDoesNotExistException;
import com.ibm.as400.access.Record;
/**
* Class encapsulating methods to write a data queue. The Record object
* which represents the data to be write to the queue is provided by the
* caller. The varible objects are supplied
* to the class <ul>
* <li>AS400 object for data queue communications</li>
* <li>The IFS path of the iSeries model input data queue object </li>
* </ul>
* The key key value used to identify this view-controller/client to the
* model/server as hex representation of last 3 bytes (least significant
* bytes) of IP address giving a six character key. The key is generated
* in the ModelOutputDataQueue class.
* <p>
* @author Bill Blalock
*
*/
public class ModelInputDataQueue {
private static AS400 as400;
private static DataQueue dq;
/**
* Construct ModelInputDataQueue. The parameters are contructed outside this class by the caller to
* make the class independent and reusable.
* @param _as400 Fully instantiated AS400 object who connection has been validated.
* @param dqIseriesPath The IFS path of the data queue object on the iSeries from the root.
* <p>
* The model input data queue object is created in the constructor from
* the values provided as parameters.
*/
public ModelInputDataQueue( AS400 _as400, String dqIseriesPath) {
as400 = _as400;
dq = new DataQueue(as400, dqIseriesPath);
}
/**
* Write the data, formatted outside the class, to the model input
* data queue.
* @param RecordFormat object of the data to be written to the data queue.
* @throws IOException
* @throws ObjectDoesNotExistException
* @throws ErrorCompletingRequestException
* @throws IllegalObjectTypeException
* @throws AS400SecurityException
* @throws InterruptedException
*/
public void writeDataQueue(Record dqRecord) throws IOException,
ObjectDoesNotExistException,
ErrorCompletingRequestException,
IllegalObjectTypeException,
AS400SecurityException,
InterruptedException
{
try {
dq.write(dqRecord.getContents());
}
catch (IOException e) {
reportException(e);
throw e;
}
catch (ObjectDoesNotExistException e) {
reportException(e);
throw e;
}
catch ( ErrorCompletingRequestException e) {
reportException(e);
throw e;
}
catch ( IllegalObjectTypeException
e) {
reportException(e);
throw e;
}
catch (
AS400SecurityException e ) {
reportException(e);
throw e;
}
catch ( InterruptedException e ) {
reportException(e);
throw e;
}
}
/**
* Report exceptions to user. When implementing for real enhance this
* method to log the exceptions.
* @param e
*/
private void reportException(Exception e) {
e.printStackTrace();
}
}