本文整理汇总了Java中org.fusesource.hawtdispatch.Dispatch类的典型用法代码示例。如果您正苦于以下问题:Java Dispatch类的具体用法?Java Dispatch怎么用?Java Dispatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Dispatch类属于org.fusesource.hawtdispatch包,在下文中一共展示了Dispatch类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setup
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Before
public void setup() throws Exception
{
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
client = new ClientInvokerImpl(queue, map);
client.start();
// server.stop();
server.registerService("service-id", new ServerInvoker.ServiceFactory()
{
public Object get()
{
return new TestServiceImpl();
}
public void unget()
{}
}, TestServiceImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", TestServiceImpl.class.getClassLoader());
testService = (TestService)Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[]{TestService.class}, handler);
}
开发者ID:apache,项目名称:aries-rsa,代码行数:27,代码来源:PromiseInvocationTest.java
示例2: onConnected
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
protected void onConnected() throws IOException {
readSource = Dispatch.createSource(channel, SelectionKey.OP_READ, dispatchQueue);
writeSource = Dispatch.createSource(channel, SelectionKey.OP_WRITE, dispatchQueue);
readSource.setCancelHandler(CANCEL_HANDLER);
writeSource.setCancelHandler(CANCEL_HANDLER);
readSource.setEventHandler(new Runnable() {
public void run() {
drainInbound();
}
});
writeSource.setEventHandler(new Runnable() {
public void run() {
drainOutbound();
}
});
if( max_read_rate!=0 || max_write_rate!=0 ) {
rateLimitingChannel = new RateLimitingChannel();
schedualRateAllowanceReset();
}
remoteAddress = channel.socket().getRemoteSocketAddress().toString();
listener.onTransportConnected(this);
}
开发者ID:apache,项目名称:aries-rsa,代码行数:28,代码来源:TcpTransport.java
示例3: setup
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Before
public void setup() throws Exception
{
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
client = new ClientInvokerImpl(queue, map);
client.start();
// server.stop();
server.registerService("service-id", new ServerInvoker.ServiceFactory()
{
public Object get()
{
return new TestServiceImpl();
}
public void unget()
{}
}, TestServiceImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", TestServiceImpl.class.getClassLoader());
testService = (TestService)Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[]{TestService.class}, handler);
Activator.INSTANCE = new Activator();
Activator.INSTANCE.client = client;
Activator.INSTANCE.server = server;
}
开发者ID:apache,项目名称:aries-rsa,代码行数:30,代码来源:StreamInvocationTest.java
示例4: testObjectMethods
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Test
public void testObjectMethods() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
final HelloImpl serviceImpl = new HelloImpl();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return serviceImpl;
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
assertNotEquals("Hashcode should be handled by the proxy and not be a remote call",-7, hello.hashCode());
assertFalse("equals should be handled by the proxy and not be a remote call",hello.equals(serviceImpl));
}
finally {
server.stop();
client.stop();
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:33,代码来源:InvocationTest.java
示例5: testNoOverflow
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Test(timeout=30*1000)
public void testNoOverflow() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
char[] chars = new char[65*1024];
String payload = new String(chars);
for(int i = 0; i < 100; i++) {
hello.hello(payload);
}
}
finally {
server.stop();
client.stop();
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:39,代码来源:InvocationTest.java
示例6: listenForConsumersOn
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
private CountDownLatch listenForConsumersOn(BrokerService broker) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
URI brokerUri = broker.getVmConnectorURI();
final ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerUri.toASCIIString());
final Connection connection = cf.createConnection();
connection.start();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = session.createTopic("ActiveMQ.Advisory.Consumer.Queue.Consumer.foo:AT_LEAST_ONCE.VirtualTopic.foo.bar");
MessageConsumer consumer = session.createConsumer(dest);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
latch.countDown();
// shutdown this connection
Dispatch.getGlobalQueue().execute(new Runnable() {
@Override
public void run() {
try {
session.close();
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
});
}
});
return latch;
}
开发者ID:apache,项目名称:activemq-artemis,代码行数:33,代码来源:MQTTNetworkOfBrokersFailoverTest.java
示例7: main
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
/**
* Only execution point for this application.
* @param args command line args.
* @throws Exception if something goes wrong.
*/
public static void main(final String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(MESSAGE_PAYLOAD)));
String payload = reader.readLine();
reader.close();
BlockingConnection publishConnection = null;
BlockingConnection subscribeConnection = null;
try {
Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE);
MQTT mqtt = new MQTT();
mqtt.setUserName(USER_NAME);
mqtt.setPassword(PASSWORD);
subscribeConnection = mqtt.blockingConnection();
subscribeConnection.connect();
subscribeConnection.subscribe(new Topic[]{outputTopic});
publishConnection = mqtt.blockingConnection();
publishConnection.connect();
publishConnection.publish(TOPIC_INPUT, payload.getBytes(), QoS.AT_LEAST_ONCE, false);
System.out.println("Published a message to " + TOPIC_INPUT + ": " + payload);
Message msg = subscribeConnection.receive(60000, TimeUnit.MILLISECONDS);
if (msg != null) {
System.out.println("Received a message from " + TOPIC_OUTPUT + ": " + new String(msg.getPayload()));
} else {
System.out.println("No message was received from " + TOPIC_OUTPUT);
}
} finally {
if (publishConnection != null && publishConnection.isConnected()) {
publishConnection.disconnect();
}
if (subscribeConnection != null && subscribeConnection.isConnected()) {
subscribeConnection.disconnect();
}
Dispatch.shutdown();
}
}
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:43,代码来源:MQTTClient.java
示例8: assertDiscriminated
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
public boolean assertDiscriminated() {
if(connection.getServiceState().isStarted() && !discriminated) {
connection.stop(Dispatch.NOOP);
return false;
}
return true;
}
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:9,代码来源:AnyProtocolHandler.java
示例9: onAccept
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Override
public void onAccept(Transport transport) throws Exception {
if (protocol != null) {
transport.setProtocolCodec(protocol.createProtocolCodec(AcceptingConnector.this));
}
accepted++;
connected++;
BrokerConnection connection = new BrokerConnection(AcceptingConnector.this, broker.getNextConnectionId());
connection.getDispatchQueue().setLabel(String.format("connection %d to %s", connection.getId(), transport.getRemoteAddress()));
connection.setProtocolHandler(protocol.createProtocolHandler());
connection.setTransport(transport);
LOG.debug("Adding new connection, connectionId={}", connection.getId());
broker.getConnections().put(connection.getId(), connection);
broker.getCurrentPeriod().setMaxConnections(Math.max(broker.getConnections().size(), broker.getCurrentPeriod().getMaxConnections()));
if (broker.getCurrentPeriod().getMaxConnections() > broker.getMaxConnectionsIn5min()) {
broker.tuneSendReceiveBuffers();
}
try {
connection.start(Dispatch.NOOP);
} catch (Exception e) {
onAcceptError(e);
}
if (atConnectionLimit()) {
// We stop accepting connections at this point.
LOG.info("Connection limit reached. Clients connected: {}", connected);
transportServer.suspend();
}
}
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:35,代码来源:AcceptingConnector.java
示例10: AbstractOverflowSink
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
public AbstractOverflowSink(Sink<T> downstream) {
refiller = Dispatch.NOOP;
this.downstream = downstream;
this.downstream.setRefiller(new Task() {
@Override
public void run() {
drain();
}
});
}
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:12,代码来源:AbstractOverflowSink.java
示例11: testDetectDummyProtocol
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Test
public void testDetectDummyProtocol() throws InterruptedException {
Dispatch.profile(true);
System.out.println("Starting test..");
// start up a connector
Broker broker = new Broker();
final AcceptingConnector connector = new AcceptingConnector(broker, "test-connector");
connector.start(new Task() {
@Override
public void run() {
assertTrue(connector.getServiceState().isStarted());
runTest(connector);
}
});
// would like to one day get rid of this sleep..
Thread.sleep(1000);
assertConnection(connector);
ServiceControl.stop(connector);
List<Metrics> metrics = Dispatch.metrics();
for (Metrics m : metrics) {
System.out.println(m.toString());
}
System.out.println("Shutting down test..");
}
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:29,代码来源:AnyProtocolDetectionTest.java
示例12: createResponse
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Override
protected ResponseFuture createResponse(SerializationStrategy serializationStrategy, ClassLoader loader, Method method, Object[] args) throws Exception {
return new AsyncResponseFuture(loader, method, serializationStrategy, Dispatch.getCurrentQueue());
}
开发者ID:apache,项目名称:aries-rsa,代码行数:5,代码来源:AsyncFutureInvocationStrategy.java
示例13: createResponse
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Override
protected ResponseFuture createResponse(SerializationStrategy serializationStrategy, ClassLoader loader, Method method, Object[] args) throws Exception {
return new AsyncResponseFuture(loader, method, (AsyncCallback) args[args.length-1], serializationStrategy, Dispatch.getCurrentQueue());
}
开发者ID:apache,项目名称:aries-rsa,代码行数:5,代码来源:AsyncInvocationStrategy.java
示例14: testInvoke
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Test(timeout=30*1000)
public void testInvoke() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
assertEquals("Hello Fabric!", hello.hello("Fabric"));
assertEquals("Hello World!", hello.helloworld());
// Verification the we can pick the right overloaded method even if using a mixure
// of primitives / objects and array dimensions.
assertEquals('a', hello.mix(0));
assertEquals('b', hello.mix(new int[]{0}));
assertEquals('c', hello.mix(new Integer(0)));
assertEquals('d', hello.mix(new Integer[]{new Integer(0)}));
assertEquals('e', hello.mix(new int[0][0]));
assertEquals('f', hello.mix(new Integer[0][0]));
AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
hello.hello("Hiram", future1);
assertEquals("Hello Hiram!", future1.get(2, TimeUnit.SECONDS));
assertEquals("Hello Hiram!", hello.protobuf(stringValue("Hiram")).getValue());
AsyncCallbackFuture<StringValue.Getter> future2 = new AsyncCallbackFuture<StringValue.Getter>();
hello.protobuf(stringValue("Hiram Async"), future2);
assertEquals("Hello Hiram Async!", future2.get(2, TimeUnit.SECONDS).getValue());
}
finally {
server.stop();
client.stop();
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:55,代码来源:InvocationTest.java
示例15: testOverflowAsync
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Test(timeout=30*1000)
public void testOverflowAsync() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
char[] chars = new char[65*1024];
String payload = new String(chars);
final List<AsyncCallbackFuture<String>> futures = new ArrayList<AsyncCallbackFuture<String>>();
for(int i = 0; i < 100; i++) {
AsyncCallbackFuture<String> future = new AsyncCallbackFuture<String>();
hello.hello(payload, future);
futures.add(future);
}
for(Future<String> f : futures) {
f.get(3, TimeUnit.SECONDS);
}
// future2.get(2, TimeUnit.SECONDS);
//assertEquals("Hello Hiram!", future1.get(2, TimeUnit.SECONDS));
//assertEquals("Hello Hiram!", hello.protobuf(stringValue(payload)).getValue());
}
finally {
server.stop();
client.stop();
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:50,代码来源:InvocationTest.java
示例16: testOverflow
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Test(timeout=30*1000)
public void testOverflow() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
final Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
final AtomicInteger requests = new AtomicInteger(0);
final AtomicInteger responses = new AtomicInteger(0);
final AtomicInteger failures = new AtomicInteger(0);
char[] chars = new char[65*1024];
final String payload = new String(chars);
Thread[] threads = new Thread[BENCHMARK_CLIENTS];
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t] = new Thread() {
public void run() {
try {
requests.incrementAndGet();
hello.hello(payload);
responses.incrementAndGet();
} catch (Throwable t) {
failures.incrementAndGet();
}
}
};
threads[t].start();
}
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t].join(10000);
System.err.format("REQUEST: %d of %d%n", requests.get(), BENCHMARK_CLIENTS);
System.err.format("RESPONSES: %d of %d%n", responses.get(), BENCHMARK_CLIENTS);
assertEquals(threads[t].isAlive(), false);
}
assertEquals(BENCHMARK_CLIENTS, requests.get());
assertEquals(BENCHMARK_CLIENTS, responses.get());
assertEquals(0, failures.get());
}
finally {
server.stop();
client.stop();
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:69,代码来源:InvocationTest.java
示例17: testInvoke
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
@Test
public void testInvoke() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[]{Hello.class}, handler);
AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
hello.hello("Guillaume", future1);
long t0 = System.currentTimeMillis();
try {
assertEquals("Hello Guillaume!", future1.get(MAX_DELAY, TimeUnit.MILLISECONDS));
fail("Should have thrown an exception");
} catch (Exception e) {
// Expected
long t1 = System.currentTimeMillis();
assertTrue(t1 - t0 > SLEEP_TIME / 2);
assertTrue(t1 - t0 < MAX_DELAY / 2);
}
}
finally {
server.stop();
client.stop();
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:47,代码来源:TransportFailureTest.java
示例18: load
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
public DispatchQueue load(String key) throws Exception {
return Dispatch.createQueue(key);
}
开发者ID:Kixeye,项目名称:kixmpp,代码行数:4,代码来源:KixmppEventEngine.java
示例19: JettyWebServer
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
public JettyWebServer(Broker broker) {
super(Dispatch.createQueue());
this.broker = broker;
}
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:5,代码来源:JettyWebServer.java
示例20: VirtualHost
import org.fusesource.hawtdispatch.Dispatch; //导入依赖的package包/类
public VirtualHost(Broker broker) {
super(Dispatch.createQueue("virtual-host"));
this.broker = broker;
}
开发者ID:christian-posta,项目名称:activemq-apollo-java-port,代码行数:5,代码来源:VirtualHost.java
注:本文中的org.fusesource.hawtdispatch.Dispatch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论