use of org.apache.mina.common.IoSession in project camel by apache.
the class MinaLoggerOptionTest method testNoLoggerOption.
@Test
public void testNoLoggerOption() throws Exception {
final String uri = "mina:tcp://localhost:{{port}}?textline=true&sync=false";
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(uri).to("mock:result");
}
});
MockEndpoint mock = this.getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
Field field = producer.getClass().getDeclaredField("session");
field.setAccessible(true);
IoSession session = (IoSession) field.get(producer);
assertFalse("There should NOT default be a logger filter", session.getFilterChain().contains("logger"));
producer.stop();
assertMockEndpointsSatisfied();
}
use of org.apache.mina.common.IoSession in project camel by apache.
the class MinaLoggerOptionTest method testLoggerOptionFalse.
@Test
public void testLoggerOptionFalse() throws Exception {
final String uri = "mina:tcp://localhost:{{port}}?textline=true&minaLogger=false&sync=false";
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(uri).to("mock:result");
}
});
MockEndpoint mock = this.getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
Field field = producer.getClass().getDeclaredField("session");
field.setAccessible(true);
IoSession session = (IoSession) field.get(producer);
assertFalse("There should NOT be a logger filter", session.getFilterChain().contains("logger"));
producer.stop();
assertMockEndpointsSatisfied();
}
use of org.apache.mina.common.IoSession in project dubbo by alibaba.
the class MinaServer method getChannels.
public Collection<Channel> getChannels() {
Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
Collection<Channel> channels = new HashSet<Channel>();
for (IoSession session : sessions) {
if (session.isConnected()) {
channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this));
}
}
return channels;
}
use of org.apache.mina.common.IoSession in project dubbo by alibaba.
the class MinaClient method doConnect.
@Override
protected void doConnect() throws Throwable {
ConnectFuture future = connector.connect(getConnectAddress(), new MinaHandler(getUrl(), this));
long start = System.currentTimeMillis();
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
// resolve future.awaitUninterruptibly() dead lock
final CountDownLatch finish = new CountDownLatch(1);
future.addListener(new IoFutureListener() {
@Override
public void operationComplete(IoFuture future) {
try {
if (future.isReady()) {
IoSession newSession = future.getSession();
try {
// Close old channel
// copy reference
IoSession oldSession = MinaClient.this.session;
if (oldSession != null) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close old mina channel " + oldSession + " on create new mina channel " + newSession);
}
oldSession.close();
} finally {
MinaChannel.removeChannelIfDisconnected(oldSession);
}
}
} finally {
if (MinaClient.this.isClosed()) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close new mina channel " + newSession + ", because the client closed.");
}
newSession.close();
} finally {
MinaClient.this.session = null;
MinaChannel.removeChannelIfDisconnected(newSession);
}
} else {
MinaClient.this.session = newSession;
}
}
}
} catch (Exception e) {
exception.set(e);
} finally {
finish.countDown();
}
}
});
try {
finish.await(getConnectTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: " + e.getMessage(), e);
}
Throwable e = exception.get();
if (e != null) {
throw e;
}
}
use of org.apache.mina.common.IoSession in project camel by apache.
the class MinaUdpProtocolCodecFactory method getEncoder.
public ProtocolEncoder getEncoder() throws Exception {
return new ProtocolEncoder() {
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
ByteBuffer buf = toByteBuffer(message);
buf.flip();
out.write(buf);
}
public void dispose(IoSession session) throws Exception {
// do nothing
}
};
}
Aggregations