[jboss-cvs] JBoss Messaging SVN: r4849 - trunk/src/main/org/jboss/messaging/core/remoting/impl/netty.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 20 03:55:46 EDT 2008
Author: trustin
Date: 2008-08-20 03:55:46 -0400 (Wed, 20 Aug 2008)
New Revision: 4849
Modified:
trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/ChannelPipelineSupport.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/MessagingChannelHandler.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyAcceptor.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnection.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnector.java
Log:
Fixed a couple more issues related with CoreClientOverSSLTest
* Made sure all connections are closed when handshake fails
* Fixed a problem where SSLEngine is not initialized properly on the acceptor side
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/ChannelPipelineSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/ChannelPipelineSupport.java 2008-08-20 06:51:04 UTC (rev 4848)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/ChannelPipelineSupport.java 2008-08-20 07:55:46 UTC (rev 4849)
@@ -64,9 +64,9 @@
final ChannelPipeline pipeline, final SSLContext context, final boolean client) throws Exception
{
SSLEngine engine = context.createSSLEngine();
+ engine.setUseClientMode(client);
if (client)
{
- engine.setUseClientMode(true);
engine.setWantClientAuth(true);
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/MessagingChannelHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/MessagingChannelHandler.java 2008-08-20 06:51:04 UTC (rev 4848)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/MessagingChannelHandler.java 2008-08-20 07:55:46 UTC (rev 4849)
@@ -45,7 +45,7 @@
private final RemotingHandler handler;
private final ConnectionLifeCycleListener listener;
- volatile boolean destroyed;
+ volatile boolean active;
MessagingChannelHandler(RemotingHandler handler, ConnectionLifeCycleListener listener)
{
@@ -65,10 +65,10 @@
{
synchronized (this)
{
- if (!destroyed)
+ if (active)
{
listener.connectionDestroyed(e.getChannel().getId());
- destroyed = true;
+ active = false;
}
}
}
@@ -76,7 +76,7 @@
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
{
- destroyed = true;
+ active = false;
}
@Override
@@ -88,7 +88,7 @@
synchronized (this)
{
- if (destroyed)
+ if (!active)
{
return;
}
@@ -97,7 +97,7 @@
me.initCause(e.getCause());
try {
listener.connectionException(e.getChannel().getId(), me);
- destroyed = true;
+ active = false;
} catch (Exception ex) {
log.error("failed to notify the listener:", ex);
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyAcceptor.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyAcceptor.java 2008-08-20 06:51:04 UTC (rev 4848)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyAcceptor.java 2008-08-20 07:55:46 UTC (rev 4849)
@@ -39,12 +39,15 @@
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.jboss.netty.handler.ssl.SslHandler;
/**
* A Netty TCP Acceptor that supports SSL
@@ -171,8 +174,26 @@
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
{
- Connection tc = new NettyConnection(e.getChannel());
- listener.connectionCreated(tc);
+ final Connection tc = new NettyConnection(e.getChannel());
+
+ SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
+ if (sslHandler != null) {
+ sslHandler.handshake(e.getChannel()).addListener(new ChannelFutureListener()
+ {
+ public void operationComplete(ChannelFuture future) throws Exception
+ {
+ if (future.isSuccess()) {
+ listener.connectionCreated(tc);
+ active = true;
+ } else {
+ future.getChannel().close();
+ }
+ }
+ });
+ } else {
+ listener.connectionCreated(tc);
+ active = true;
+ }
}
}
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnection.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnection.java 2008-08-20 06:51:04 UTC (rev 4848)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnection.java 2008-08-20 07:55:46 UTC (rev 4849)
@@ -84,7 +84,7 @@
// A client channel - wait until everything is cleaned up.
// TODO Do not spin - use signal.
MessagingChannelHandler handler = (MessagingChannelHandler) channel.getPipeline().get("handler");
- while (!handler.destroyed) {
+ while (handler.active) {
Thread.yield();
}
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnector.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnector.java 2008-08-20 06:51:04 UTC (rev 4848)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/netty/NettyConnector.java 2008-08-20 07:55:46 UTC (rev 4849)
@@ -28,6 +28,7 @@
import java.util.concurrent.Executors;
import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLException;
import org.jboss.messaging.core.client.ConnectionParams;
import org.jboss.messaging.core.client.Location;
@@ -38,13 +39,13 @@
import org.jboss.messaging.core.remoting.spi.Connection;
import org.jboss.messaging.core.remoting.spi.Connector;
import org.jboss.netty.bootstrap.ClientBootstrap;
+import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelFuture;
-import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.handler.ssl.SslHandler;
@@ -143,6 +144,7 @@
}
catch (Exception e)
{
+ close();
IllegalStateException ise = new IllegalStateException(
"Unable to create NettyConnector for " + location);
ise.initCause(e);
@@ -182,12 +184,43 @@
public Connection createConnection()
{
+ if (channelFactory == null) {
+ return null;
+ }
+
InetSocketAddress address = new InetSocketAddress(location.getHost(), location.getPort());
ChannelFuture future = bootstrap.connect(address);
future.awaitUninterruptibly();
if (future.isSuccess())
{
+ final Channel ch = future.getChannel();
+ SslHandler sslHandler = ch.getPipeline().get(SslHandler.class);
+ if (sslHandler != null) {
+ log.info("Starting SSL handshake.");
+ try
+ {
+ sslHandler.handshake(ch).addListener(new ChannelFutureListener()
+ {
+ public void operationComplete(ChannelFuture future) throws Exception
+ {
+ if (future.isSuccess()) {
+ ch.getPipeline().get(MessagingChannelHandler.class).active = true;
+ } else {
+ ch.close();
+ }
+ }
+ });
+ }
+ catch (SSLException e)
+ {
+ ch.close();
+ return null;
+ }
+ } else {
+ ch.getPipeline().get(MessagingChannelHandler.class).active = true;
+ }
+
return new NettyConnection(future.getChannel());
}
else
@@ -213,15 +246,5 @@
{
super(handler, listener);
}
-
- @Override
- public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
- {
- SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
- if (sslHandler != null) {
- log.info("Starting SSL handshake.");
- sslHandler.handshake(e.getChannel());
- }
- }
}
}
More information about the jboss-cvs-commits
mailing list