本文整理汇总了Java中org.apache.cassandra.net.OutboundTcpConnectionPool类的典型用法代码示例。如果您正苦于以下问题:Java OutboundTcpConnectionPool类的具体用法?Java OutboundTcpConnectionPool怎么用?Java OutboundTcpConnectionPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OutboundTcpConnectionPool类属于org.apache.cassandra.net包,在下文中一共展示了OutboundTcpConnectionPool类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConnection
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Connect to peer and start exchanging message.
* When connect attempt fails, this retries for maximum of MAX_CONNECT_ATTEMPTS times.
*
* @param peer the peer to connect to.
* @return the created socket.
*
* @throws IOException when connection failed.
*/
public Socket createConnection(InetAddress peer) throws IOException
{
int attempts = 0;
while (true)
{
try
{
Socket socket = OutboundTcpConnectionPool.newSocket(peer);
socket.setSoTimeout(DatabaseDescriptor.getStreamingSocketTimeout());
socket.setKeepAlive(true);
return socket;
}
catch (IOException e)
{
if (++attempts >= MAX_CONNECT_ATTEMPTS)
throw e;
long waitms = DatabaseDescriptor.getRpcTimeout() * (long)Math.pow(2, attempts);
logger.warn("Failed attempt " + attempts + " to connect to " + peer + ". Retrying in " + waitms + " ms. (" + e + ")");
try
{
Thread.sleep(waitms);
}
catch (InterruptedException wtf)
{
throw new IOException("interrupted", wtf);
}
}
}
}
示例2: testEc2MRSnitch
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
@Test
public void testEc2MRSnitch() throws UnknownHostException
{
InetAddress me = InetAddress.getByName("127.0.0.2");
InetAddress com_ip = InetAddress.getByName("127.0.0.3");
OutboundTcpConnectionPool pool = MessagingService.instance().getConnectionPool(me);
Assert.assertEquals(me, pool.endPoint());
pool.reset(com_ip);
Assert.assertEquals(com_ip, pool.endPoint());
MessagingService.instance().destroyConnectionPool(me);
pool = MessagingService.instance().getConnectionPool(me);
Assert.assertEquals(com_ip, pool.endPoint());
}
示例3: connect
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Connect to peer and start exchanging message.
* When connect attempt fails, this retries for maximum of MAX_CONNECT_ATTEMPTS times.
*
* @param peer the peer to connect to.
* @return the created socket.
*
* @throws IOException when connection failed.
*/
private static Socket connect(InetAddress peer) throws IOException
{
int attempts = 0;
while (true)
{
try
{
Socket socket = OutboundTcpConnectionPool.newSocket(peer);
socket.setSoTimeout(DatabaseDescriptor.getStreamingSocketTimeout());
return socket;
}
catch (IOException e)
{
if (++attempts >= MAX_CONNECT_ATTEMPTS)
throw e;
long waitms = DatabaseDescriptor.getRpcTimeout() * (long)Math.pow(2, attempts);
logger.warn("Failed attempt " + attempts + " to connect to " + peer + ". Retrying in " + waitms + " ms. (" + e + ")");
try
{
Thread.sleep(waitms);
}
catch (InterruptedException wtf)
{
throw new IOException("interrupted", wtf);
}
}
}
}
示例4: createConnection
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Connect to peer and start exchanging message.
* When connect attempt fails, this retries for maximum of MAX_CONNECT_ATTEMPTS times.
*
* @param peer the peer to connect to.
* @return the created socket.
*
* @throws IOException when connection failed.
*/
public Socket createConnection(InetAddress peer) throws IOException
{
int attempts = 0;
while (true)
{
try
{
Socket socket = OutboundTcpConnectionPool.newSocket(peer);
socket.setSoTimeout(DatabaseDescriptor.getStreamingSocketTimeout());
socket.setKeepAlive(true);
return socket;
}
catch (IOException e)
{
if (++attempts >= MAX_CONNECT_ATTEMPTS)
throw e;
long waitms = DatabaseDescriptor.getRpcTimeout() * (long)Math.pow(2, attempts);
logger.warn("Failed attempt {} to connect to {}. Retrying in {} ms. ({})", attempts, peer, waitms, e);
try
{
Thread.sleep(waitms);
}
catch (InterruptedException wtf)
{
throw new IOException("interrupted", wtf);
}
}
}
}
示例5: connect
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Connect to peer and start exchanging message.
* When connect attempt fails, this retries for maximum of MAX_CONNECT_ATTEMPTS times.
*
* @param peer the peer to connect to.
* @return the created socket.
*
* @throws IOException when connection failed.
*/
private static Socket connect(InetAddress peer) throws IOException
{
int attempts = 0;
while (true)
{
try
{
Socket socket = OutboundTcpConnectionPool.newSocket(peer);
socket.setSoTimeout(DatabaseDescriptor.getStreamingSocketTimeout());
return socket;
}
catch (IOException e)
{
if (++attempts >= MAX_CONNECT_ATTEMPTS)
throw e;
long waitms = DatabaseDescriptor.getRpcTimeout() * (long)Math.pow(2, attempts);
logger.warn("Failed attempt {} to connect to {}. Retrying in {} ms. ({})", attempts, peer, waitms, e);
try
{
Thread.sleep(waitms);
}
catch (InterruptedException wtf)
{
throw new IOException("interrupted", wtf);
}
}
}
}
示例6: ConnectionMetrics
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Create metrics for given connection pool.
*
* @param ip IP address to use for metrics label
* @param connectionPool Connection pool
*/
public ConnectionMetrics(InetAddress ip, final OutboundTcpConnectionPool connectionPool)
{
// ipv6 addresses will contain colons, which are invalid in a JMX ObjectName
address = ip.getHostAddress().replace(':', '.');
factory = new DefaultNameFactory("Connection", address);
commandPendingTasks = Metrics.newGauge(factory.createMetricName("CommandPendingTasks"), new Gauge<Integer>()
{
public Integer value()
{
return connectionPool.cmdCon.getPendingMessages();
}
});
commandCompletedTasks = Metrics.newGauge(factory.createMetricName("CommandCompletedTasks"), new Gauge<Long>()
{
public Long value()
{
return connectionPool.cmdCon.getCompletedMesssages();
}
});
commandDroppedTasks = Metrics.newGauge(factory.createMetricName("CommandDroppedTasks"), new Gauge<Long>()
{
public Long value()
{
return connectionPool.cmdCon.getDroppedMessages();
}
});
responsePendingTasks = Metrics.newGauge(factory.createMetricName("ResponsePendingTasks"), new Gauge<Integer>()
{
public Integer value()
{
return connectionPool.ackCon.getPendingMessages();
}
});
responseCompletedTasks = Metrics.newGauge(factory.createMetricName("ResponseCompletedTasks"), new Gauge<Long>()
{
public Long value()
{
return connectionPool.ackCon.getCompletedMesssages();
}
});
timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS);
}
示例7: ConnectionMetrics
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Create metrics for given connection pool.
*
* @param ip IP address to use for metrics label
* @param connectionPool Connection pool
*/
public ConnectionMetrics(InetAddress ip, final OutboundTcpConnectionPool connectionPool)
{
// ipv6 addresses will contain colons, which are invalid in a JMX ObjectName
address = ip.getHostAddress().replaceAll(":", ".");
factory = new DefaultNameFactory("Connection", address);
commandPendingTasks = Metrics.newGauge(factory.createMetricName("CommandPendingTasks"), new Gauge<Integer>()
{
public Integer value()
{
return connectionPool.cmdCon.getPendingMessages();
}
});
commandCompletedTasks = Metrics.newGauge(factory.createMetricName("CommandCompletedTasks"), new Gauge<Long>()
{
public Long value()
{
return connectionPool.cmdCon.getCompletedMesssages();
}
});
commandDroppedTasks = Metrics.newGauge(factory.createMetricName("CommandDroppedTasks"), new Gauge<Long>()
{
public Long value()
{
return connectionPool.cmdCon.getDroppedMessages();
}
});
responsePendingTasks = Metrics.newGauge(factory.createMetricName("ResponsePendingTasks"), new Gauge<Integer>()
{
public Integer value()
{
return connectionPool.ackCon.getPendingMessages();
}
});
responseCompletedTasks = Metrics.newGauge(factory.createMetricName("ResponseCompletedTasks"), new Gauge<Long>()
{
public Long value()
{
return connectionPool.ackCon.getCompletedMesssages();
}
});
timeouts = Metrics.newMeter(factory.createMetricName("Timeouts"), "timeouts", TimeUnit.SECONDS);
}
示例8: ConnectionMetrics
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Create metrics for given connection pool.
*
* @param ip IP address to use for metrics label
* @param connectionPool Connection pool
*/
public ConnectionMetrics(InetAddress ip, final OutboundTcpConnectionPool connectionPool)
{
// ipv6 addresses will contain colons, which are invalid in a JMX ObjectName
address = ip.getHostAddress().replace(':', '.');
factory = new DefaultNameFactory("Connection", address);
largeMessagePendingTasks = Metrics.register(factory.createMetricName("LargeMessagePendingTasks"), new Gauge<Integer>()
{
public Integer getValue()
{
return connectionPool.largeMessages.getPendingMessages();
}
});
largeMessageCompletedTasks = Metrics.register(factory.createMetricName("LargeMessageCompletedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.largeMessages.getCompletedMesssages();
}
});
largeMessageDroppedTasks = Metrics.register(factory.createMetricName("LargeMessageDroppedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.largeMessages.getDroppedMessages();
}
});
smallMessagePendingTasks = Metrics.register(factory.createMetricName("SmallMessagePendingTasks"), new Gauge<Integer>()
{
public Integer getValue()
{
return connectionPool.smallMessages.getPendingMessages();
}
});
smallMessageCompletedTasks = Metrics.register(factory.createMetricName("SmallMessageCompletedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.smallMessages.getCompletedMesssages();
}
});
smallMessageDroppedTasks = Metrics.register(factory.createMetricName("SmallMessageDroppedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.smallMessages.getDroppedMessages();
}
});
gossipMessagePendingTasks = Metrics.register(factory.createMetricName("GossipMessagePendingTasks"), new Gauge<Integer>()
{
public Integer getValue()
{
return connectionPool.gossipMessages.getPendingMessages();
}
});
gossipMessageCompletedTasks = Metrics.register(factory.createMetricName("GossipMessageCompletedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.gossipMessages.getCompletedMesssages();
}
});
gossipMessageDroppedTasks = Metrics.register(factory.createMetricName("GossipMessageDroppedTasks"), new Gauge<Long>()
{
public Long getValue()
{
return connectionPool.gossipMessages.getDroppedMessages();
}
});
timeouts = Metrics.meter(factory.createMetricName("Timeouts"));
}
示例9: ConnectionMetrics
import org.apache.cassandra.net.OutboundTcpConnectionPool; //导入依赖的package包/类
/**
* Create metrics for given connection pool.
*
* @param ip IP address to use for metrics label
* @param connectionPool Connection pool
*/
public ConnectionMetrics(InetAddress ip, final OutboundTcpConnectionPool connectionPool)
{
// ipv6 addresses will contain colons, which are invalid in a JMX ObjectName
address = ip.getHostAddress().replaceAll(":", ".");
commandPendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandPendingTasks", address), new Gauge<Integer>()
{
public Integer value()
{
return connectionPool.cmdCon.getPendingMessages();
}
});
commandCompletedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandCompletedTasks", address), new Gauge<Long>()
{
public Long value()
{
return connectionPool.cmdCon.getCompletedMesssages();
}
});
commandDroppedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "CommandDroppedTasks", address), new Gauge<Long>()
{
public Long value()
{
return connectionPool.cmdCon.getDroppedMessages();
}
});
responsePendingTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "ResponsePendingTasks", address), new Gauge<Integer>()
{
public Integer value()
{
return connectionPool.ackCon.getPendingMessages();
}
});
responseCompletedTasks = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "ResponseCompletedTasks", address), new Gauge<Long>()
{
public Long value()
{
return connectionPool.ackCon.getCompletedMesssages();
}
});
timeouts = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Timeouts", address), "timeouts", TimeUnit.SECONDS);
}