use of org.apache.mina.core.future.ConnectFuture in project opennms by OpenNMS.
the class ConnectionFactoryNewConnectorImpl method connect.
/**
* <p>Connect to a remote socket. If org.opennms.netmgt.provision.maxConcurrentConnections
* is set, this may block until a connection slot is available.</p>
*
* <p>You must dispose both the {@link ConnectionFactoryNewConnectorImpl} and {@link ConnectFuture} when done
* by calling {@link #dispose(ConnectionFactoryNewConnectorImpl, ConnectFuture)}.</p>
*
* @param remoteAddress
* Destination address
* @param init
* Initialiser for the IoSession
* @return
* ConnectFuture from a Mina connect call
*/
@Override
public ConnectFuture connect(SocketAddress remoteAddress, IoSessionInitializer<? extends ConnectFuture> init, IoHandler handler) {
SocketConnector connector = getSocketConnector(getTimeout(), handler);
InetSocketAddress localAddress = null;
synchronized (m_portMutex) {
if (m_port.get() == null) {
// Fetch a new ephemeral port
localAddress = new InetSocketAddress(0);
m_port.set(localAddress.getPort());
} else {
localAddress = new InetSocketAddress(m_port.get());
}
}
final ConnectFuture cf = connector.connect(remoteAddress, localAddress, init);
cf.addListener(portSwitcher(connector, remoteAddress, init, handler));
cf.addListener(connectorDisposer(connector));
return cf;
}
use of org.apache.mina.core.future.ConnectFuture in project cxf by apache.
the class UDPConduit method close.
public void close(Message msg) throws IOException {
super.close(msg);
if (msg.getExchange().isOneWay() || msg.getExchange().getInMessage() == msg || msg.getExchange().getInFaultMessage() == msg) {
String s = (String) msg.getExchange().get(HOST_PORT);
ConnectFuture c = msg.getExchange().get(ConnectFuture.class);
if (s != null && c != null) {
c.getSession().removeAttribute(CXF_MESSAGE_ATTR);
Queue<ConnectFuture> q = connections.get(s);
if (q == null) {
connections.putIfAbsent(s, new ArrayBlockingQueue<ConnectFuture>(10));
q = connections.get(s);
}
if (!q.offer(c)) {
c.getSession().closeOnFlush();
}
}
}
}
use of org.apache.mina.core.future.ConnectFuture in project pancm_project by xuwujing.
the class ClientTestServer method getIOSession.
/**
* Get io session io session.
*
* @param connector the connector
* @return the io session
*/
public IoSession getIOSession(IoConnector connector) {
ConnectFuture future = connector.connect(new InetSocketAddress("192.168.2.55", 1255));
// 等待是否连接成功,相当于是转异步执行为同步执行。
future.awaitUninterruptibly();
// 连接成功后获取会话对象。 如果没有上面的等待, 由于connect()方法是异步的, session可能会无法获取。
IoSession session = null;
try {
session = future.getSession();
} catch (Exception e) {
e.printStackTrace();
}
return session;
}
use of org.apache.mina.core.future.ConnectFuture in project streamsx.topology by IBMStreams.
the class TCPTestClient method connect.
public synchronized void connect() throws InterruptedException {
for (int i = 0; i < 5; i++) {
try {
TRACE.info("Attempting to connect to test collector: " + addr);
ConnectFuture future = connector.connect(addr);
future.awaitUninterruptibly();
session = future.getSession();
TRACE.info("Connected to test collector: " + addr);
return;
} catch (RuntimeIoException e) {
e.printStackTrace(System.err);
if (i < 4) {
TRACE.warning("Failed to connect to test collector - retrying: " + addr);
Thread.sleep(1000);
} else {
TRACE.severe("Failed to connect to test collector: " + addr);
throw e;
}
}
}
}
Aggregations