use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.
the class ConnectChannelHandlerTest method test_Received_Event_invoke_direct.
/**
* Events do not pass through the thread pool and execute directly on the IO
*/
@SuppressWarnings("deprecation")
@Disabled("Heartbeat is processed in HeartbeatHandler not WrappedChannelHandler.")
@Test
public void test_Received_Event_invoke_direct() throws RemotingException {
handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
ThreadPoolExecutor executor = (ThreadPoolExecutor) getField(handler, "SHARED_EXECUTOR", 1);
executor.shutdown();
executor = (ThreadPoolExecutor) getField(handler, "executor", 1);
executor.shutdown();
Request req = new Request();
req.setHeartbeat(true);
final AtomicInteger count = new AtomicInteger(0);
handler.received(new MockedChannel() {
@Override
public void send(Object message) throws RemotingException {
Assertions.assertTrue(((Response) message).isHeartbeat(), "response.heartbeat");
count.incrementAndGet();
}
}, req);
Assertions.assertEquals(1, count.get(), "channel.send must be invoke");
}
use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.
the class GrizzlyChannel method send.
@Override
@SuppressWarnings("rawtypes")
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent);
int timeout = 0;
try {
GrizzlyFuture future = connection.write(message);
if (sent) {
timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
future.get(timeout, TimeUnit.MILLISECONDS);
}
} catch (TimeoutException e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e);
} catch (Throwable e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
}
}
use of org.apache.dubbo.remoting.RemotingException 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.dubbo.remoting.RemotingException in project dubbo by alibaba.
the class GrizzlyHandler method handleConnect.
@Override
public NextAction handleConnect(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.connected(channel);
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnected(connection);
}
return ctx.getInvokeAction();
}
use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.
the class GrizzlyHandler method handleClose.
@Override
public NextAction handleClose(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.disconnected(channel);
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnected(connection);
}
return ctx.getInvokeAction();
}
Aggregations