3

キューをの先頭に配線しようとしていますが、トリガーさMessageChannelれたときに実行時に実行できるように、プログラムで配線する必要があります。osgi:listenerこれまでのところ私は持っています:

public void addService(MessageChannel mc, Map<String,Object> properties)
{
    //Create the queue and the QueueChannel
    BlockingQueue<Message<?>> q = new LinkedBlockingQueue<Message<?>>();
    QueueChannel qc = new QueueChannel(q);

    //Create the Bridge and set the output to the input parameter channel
    BridgeHandler b = new BridgeHandler();
    b.setOutputChannel(mc);

    //Presumably, I need something here to poll the QueueChannel
    //and drop it onto the bridge.  This is where I get lost

}

関連するさまざまなクラスを調べて、私は次のことを思いつきました。

    PollerMetadata pm = new PollerMetadata();
    pm.setTrigger(new IntervalTrigger(10));

    PollingConsumer pc = new PollingConsumer(qc, b);

しかし、私はそれをすべてまとめることはできません。私は何が欠けていますか?

4

1 に答える 1

0

だから、私のために働くことになった解決策は次のとおりでした:

public void addEngineService(MessageChannel mc, Map<String,Object> properties)
{
    //Create the queue and the QueueChannel
    BlockingQueue<Message<?>> q = new LinkedBlockingQueue<Message<?>>();
    QueueChannel qc = new QueueChannel(q);

    //Create the Bridge and set the output to the input parameter channel 
    BridgeHandler b = new BridgeHandler();
    b.setOutputChannel(mc);

    //Setup a Polling Consumer to poll the queue channel and 
    //retrieve 1 thing at a time
    PollingConsumer pc = new PollingConsumer(qc, b);
    pc.setMaxMessagesPerPoll(1);

    //Now use an interval trigger to poll every 10 ms and attach it
    IntervalTrigger trig = new IntervalTrigger(10, TimeUnit.MILLISECONDS);
    trig.setInitialDelay(0);
    trig.setFixedRate(true);
    pc.setTrigger(trig);

    //Now set a task scheduler and start it
    pc.setTaskScheduler(taskSched);
    pc.setAutoStartup(true);
    pc.start();
}

上記のすべてが明示的に必要かどうかははっきりしていませんが、トリガーもタスクスケジューラも単独では機能せず、両方が必要であるように見えました。また、使用されたtaskSchedは、春から経由して注入されたデフォルトのtaskScheduler依存関係であったことに注意する必要があります。

<property name="taskSched" ref="taskScheduler"/>
于 2010-04-05T14:42:21.083 に答える