import com.ms.com.*;
import mqoa.*; public class MSMQClientSink
implements mqoa._DMSMQEventEvents,
Runnable
{
// The ConnectionPointCookie
member is global so that it
// exists for the life of an instance of this
class
private ConnectionPointCookie cookie;
private IMSMQQueue queue;
private IMSMQEvent msmqEvent;
private Variant variantTrue = new Variant();
private Variant variantNoParam = new Variant();
//====================================================================
public MSMQClientSink()
{
// Creating the member event
object and setting some
// variables.
msmqEvent = new MSMQEvent();
variantTrue.putBoolean(true);
variantNoParam.noParam();
}
//====================================================================
public static void main(String[]
args)
{
try
{
Thread sink = new Thread(
new MSMQClientSink() );
sink.start();
Thread.currentThread().join();
}
catch(Exception e)
{
}
}
//====================================================================
public void Arrived(Object
Queue, int Cursor)
{
IMSMQMessage message = null;
IMSMQTransactionDispenser
transactionDispenser = new MSMQTransactionDispenser();
IMSMQTransaction transaction;
Variant oneSecondDelay = new
Variant();
Variant transactionHolder = new
Variant();
oneSecondDelay.putInt(1000);
// Casting the Object parameter to
the appropriate
// IMSMQQueue variable
queue = (IMSMQQueue)Queue;
// Starting a transaction
transaction =
transactionDispenser.BeginTransaction();
try
{
//
Wrapping the transaction object in a Variant
transactionHolder.putDispatch(transaction);
//
Receiving a message transactionally
message =
queue.Receive(transactionHolder,variantTrue,variantTrue,oneSecondDelay);
//
Committing the transaction
transaction.Commit(variantNoParam,variantNoParam,variantNoParam);
}
catch(Exception transactionFailed)
{
//
Aborting the transaction
transaction.Abort(variantNoParam,variantNoParam);
}
if(message != null)
{
//
Displaying the message body in the windows message box
com.ms.wfc.ui.MessageBox.show((String)message.getBody().toString());
}
// Resetting the event
mechanism
queue.EnableNotification(msmqEvent,variantNoParam,variantNoParam);
}
//====================================================================
public void ArrivedError(Object
Queue, int ErrorCode, int Cursor)
{
// Display a windows message box with an error message
com.ms.wfc.ui.MessageBox.show("Error!");
// Resetting the event
mechanism
queue.EnableNotification(msmqEvent,variantNoParam,variantNoParam);
}
//====================================================================
public void run()
{
// This is the typeID that will be
associated
// with the existing queue(s)
String typeID =
"{E9E8CB90-D05E-11d2-B9D0-006097A7D34F}";
Variant guid = new Variant();
Variant nop = new
Variant((int)RELOPS.REL_NOP);
Variant isEqual = new
Variant((int)RELOPS.REL_EQ);
IMSMQQueueInfo queryInfo;
IMSMQQueueInfos qInfos;
IMSMQQuery query = new MSMQQuery();
guid.putString(typeID);
qInfos =
query.LookupQueue(variantNoParam, guid,
variantNoParam, variantNoParam, variantNoParam,
isEqual, nop, nop, nop);
qInfos.Reset();
queryInfo = qInfos.Next();
try
{
cookie = new
ConnectionPointCookie(msmqEvent, this,
Class.forName("mqoa._DMSMQEventEvents"));
}
catch(ClassNotFoundException
notFoundException)
{
//
Display a windows message box with an error message
com.ms.wfc.ui.MessageBox.show("Error -
ClassNotFoundException!");
}
while(queryInfo != null)
{
queue =
queryInfo.Open(MQACCESS.MQ_RECEIVE_ACCESS,MQSHARE.MQ_DENY_NONE);
try
{
queue.EnableNotification(msmqEvent, variantNoParam,
variantNoParam);
}
catch(ComSuccessException
comException)
{
//
Display a windows message box with an error message
com.ms.wfc.ui.MessageBox.show("Error -
ComSuccessException!");
}
queryInfo =
qInfos.Next();
}
}
//====================================================================
}
|