本文整理汇总了Java中org.apache.activemq.artemis.api.core.client.ServerLocator.setClientFailureCheckPeriod方法的典型用法代码示例。如果您正苦于以下问题:Java ServerLocator.setClientFailureCheckPeriod方法的具体用法?Java ServerLocator.setClientFailureCheckPeriod怎么用?Java ServerLocator.setClientFailureCheckPeriod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.activemq.artemis.api.core.client.ServerLocator
的用法示例。
在下文中一共展示了ServerLocator.setClientFailureCheckPeriod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
try {
CrashClient.log.debug("args = " + Arrays.asList(args));
ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
locator.setClientFailureCheckPeriod(ClientCrashTest.PING_PERIOD);
locator.setConnectionTTL(ClientCrashTest.CONNECTION_TTL);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, true, true);
ClientProducer producer = session.createProducer(ClientCrashTest.QUEUE);
// it has to be durable otherwise it may race dying before the client is killed
ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 1);
message.getBodyBuffer().writeString(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT);
producer.send(message);
// exit without closing the session properly
System.exit(9);
} catch (Throwable t) {
CrashClient.log.error(t.getMessage(), t);
System.exit(1);
}
}
示例2: main
import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
try {
log.debug("args = " + Arrays.asList(args));
ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
locator.setClientFailureCheckPeriod(ClientCrashTest.PING_PERIOD);
locator.setConnectionTTL(ClientCrashTest.CONNECTION_TTL);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(true, true, 1000000);
ClientProducer producer = session.createProducer(ClientCrashTest.QUEUE2);
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT);
producer.send(message);
//Now consume the message, but don't let ack get to server
//Consume the message
ClientConsumer cons = session.createConsumer(ClientCrashTest.QUEUE2);
session.start();
ClientMessage msg = cons.receive(10000);
if (msg == null) {
log.error("Didn't receive msg");
System.exit(1);
}
// exit without closing the session properly
System.exit(9);
} catch (Throwable t) {
log.error(t.getMessage(), t);
System.exit(1);
}
}
示例3: testServerFailureNoPing
import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testServerFailureNoPing() throws Exception {
TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
locator.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD);
locator.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2);
ClientSessionFactoryImpl csf = (ClientSessionFactoryImpl) createSessionFactory(locator);
Listener clientListener = new Listener();
ClientSession session = csf.createSession(false, true, true);
Assert.assertEquals(1, csf.numConnections());
session.addFailureListener(clientListener);
// We need to get it to stop pinging after one
csf.stopPingingAfterOne();
RemotingConnection serverConn = null;
while (serverConn == null) {
Set<RemotingConnection> conns = server.getRemotingService().getConnections();
if (!conns.isEmpty()) {
serverConn = server.getRemotingService().getConnections().iterator().next();
} else {
// It's async so need to wait a while
Thread.sleep(10);
}
}
Listener serverListener = new Listener();
serverConn.addFailureListener(serverListener);
for (int i = 0; i < 1000; i++) {
// a few tries to avoid a possible race caused by GCs or similar issues
if (server.getRemotingService().getConnections().isEmpty() && clientListener.getException() != null) {
break;
}
Thread.sleep(10);
}
if (!server.getRemotingService().getConnections().isEmpty()) {
RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();
PingTest.log.info("Serverconn2 is " + serverConn2);
}
Assert.assertTrue(server.getRemotingService().getConnections().isEmpty());
// The client listener should be called too since the server will close it from the server side which will result
// in the
// netty detecting closure on the client side and then calling failure listener
Assert.assertNotNull(clientListener.getException());
Assert.assertNotNull(serverListener.getException());
session.close();
csf.close();
locator.close();
}
示例4: internalMetadataAfterRetry
import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public void internalMetadataAfterRetry(final boolean isNetty) throws Exception {
final int pingPeriod = 1000;
ActiveMQServer server = createServer(false, isNetty);
server.start();
ClientSessionInternal session = null;
try {
for (int i = 0; i < 100; i++) {
ServerLocator locator = createFactory(isNetty);
locator.setClientFailureCheckPeriod(pingPeriod);
locator.setRetryInterval(1);
locator.setRetryIntervalMultiplier(1d);
locator.setReconnectAttempts(-1);
locator.setConfirmationWindowSize(-1);
ClientSessionFactory factory = createSessionFactory(locator);
session = (ClientSessionInternal) factory.createSession();
session.addMetaData("meta1", "meta1");
ServerSession[] sessions = countMetadata(server, "meta1", 1);
Assert.assertEquals(1, sessions.length);
final AtomicInteger count = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(1);
session.addFailoverListener(new FailoverEventListener() {
@Override
public void failoverEvent(FailoverEventType eventType) {
if (eventType == FailoverEventType.FAILOVER_COMPLETED) {
latch.countDown();
}
}
});
sessions[0].getRemotingConnection().fail(new ActiveMQException("failure!"));
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
sessions = countMetadata(server, "meta1", 1);
Assert.assertEquals(1, sessions.length);
locator.close();
}
} finally {
try {
session.close();
} catch (Throwable e) {
}
server.stop();
}
}
示例5: testNoFailureWithPinging
import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testNoFailureWithPinging() throws Exception {
ServerLocator locator = createNettyNonHALocator();
locator.setClientFailureCheckPeriod(PingTest.CLIENT_FAILURE_CHECK_PERIOD);
locator.setConnectionTTL(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 2);
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession(false, true, true);
PingTest.log.info("Created session");
Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());
Listener clientListener = new Listener();
session.addFailureListener(clientListener);
RemotingConnection serverConn = null;
while (serverConn == null) {
Set<RemotingConnection> conns = server.getRemotingService().getConnections();
if (!conns.isEmpty()) {
serverConn = server.getRemotingService().getConnections().iterator().next();
} else {
// It's async so need to wait a while
Thread.sleep(10);
}
}
Listener serverListener = new Listener();
serverConn.addFailureListener(serverListener);
Thread.sleep(PingTest.CLIENT_FAILURE_CHECK_PERIOD * 10);
Assert.assertNull(clientListener.getException());
Assert.assertNull(serverListener.getException());
RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();
PingTest.log.info("Server conn2 is " + serverConn2);
Assert.assertTrue(serverConn == serverConn2);
session.close();
csf.close();
locator.close();
}
示例6: testNoFailureNoPinging
import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testNoFailureNoPinging() throws Exception {
TransportConfiguration transportConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
ServerLocator locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(transportConfig));
locator.setClientFailureCheckPeriod(-1);
locator.setConnectionTTL(-1);
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession(false, true, true);
Assert.assertEquals(1, ((ClientSessionFactoryInternal) csf).numConnections());
Listener clientListener = new Listener();
session.addFailureListener(clientListener);
RemotingConnection serverConn = null;
while (serverConn == null) {
Set<RemotingConnection> conns = server.getRemotingService().getConnections();
if (!conns.isEmpty()) {
serverConn = server.getRemotingService().getConnections().iterator().next();
} else {
// It's async so need to wait a while
Thread.sleep(10);
}
}
Listener serverListener = new Listener();
serverConn.addFailureListener(serverListener);
Thread.sleep(ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD);
Assert.assertNull(clientListener.getException());
Assert.assertNull(serverListener.getException());
RemotingConnection serverConn2 = server.getRemotingService().getConnections().iterator().next();
PingTest.log.info("Serverconn2 is " + serverConn2);
Assert.assertTrue(serverConn == serverConn2);
session.close();
csf.close();
locator.close();
}