mtdatahandleradapter.java
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· Java 代码 · 共 81 行
JAVA
81 行
// MTDataHandlerAdapter.java,v 1.3 1999/11/19 23:57:33 cdgill Exp
// This is an adapter class for a data handler to be used in a separate
// thread. The adapter provides a push method that places an event
// set into its synchronized internal MTQueue. It runs a separate thread
// which blocks until there is an event in the queue, then dequeues the
// event and then unpacks it and updates the underlying data handler.
public class MTDataHandlerAdapter extends Thread
{
// Both the queue and the underlying data handler are private
private MTQueue queue_ = null;
private DataHandler dataHandler_ = null;
private boolean use_queueing_ = false;
// Constructor.
MTDataHandlerAdapter (DataHandler dh, boolean use_queueing)
{
dataHandler_ = dh;
use_queueing_ = use_queueing;
if (use_queueing_)
{
queue_ = new MTQueue ();
}
}
// Enqueue an event set for the handler thread.
public void push (RtecEventComm.Event[] events)
{
// System.out.println ("in MTDataHandlerAdapter.push");
if (use_queueing_)
{
// System.out.println ("MTDataHandlerAdapter.push queueing events");
queue_.enqueue_tail (events);
}
else
{
for (int i = 0; i < events.length; ++i)
{
if(events[i].header.type ==
PushConsumer.ACE_ES_EVENT_NOTIFICATION)
{
// System.out.println ("MTDataHandlerAdapter.push updating data handler");
dataHandler_.update (events[i]);
}
}
}
}
// Process enqueued event sets in a separate thread.
public void run ()
{
// Loop forever, handling events.
for (;;)
{
try
{
// Pull an event set from the head of the queue
RtecEventComm.Event[] events =
(RtecEventComm.Event[]) queue_.dequeue_head ();
for (int i = 0; i < events.length; ++i)
{
if(events[i].header.type ==
PushConsumer.ACE_ES_EVENT_NOTIFICATION)
{
dataHandler_.update (events[i]);
}
}
}
catch(org.omg.CORBA.SystemException e)
{
System.err.println(e);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?