Author: richard.opalka(a)jboss.com
Date: 2009-10-17 20:04:03 -0400 (Sat, 17 Oct 2009)
New Revision: 10949
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/RMClientSequence.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMCallbackHandlerFactory.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMRequestHandlerFactory.java
Log:
fixed RM regression - mostly synchronization issues
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java 2009-10-17
20:53:10 UTC (rev 10948)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java 2009-10-18
00:04:03 UTC (rev 10949)
@@ -23,8 +23,6 @@
import java.util.LinkedList;
import java.util.List;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage;
@@ -46,9 +44,6 @@
/** Callbacks registry. */
private final List<NettyCallbackHandler> callbacks = new
LinkedList<NettyCallbackHandler>();
- /** Callback registry lock. */
- private final Lock callbackRegistryLock = new ReentrantLock();
-
/**
* Constructor.
*/
@@ -104,15 +99,7 @@
*/
public final boolean hasMoreCallbacks()
{
- this.callbackRegistryLock.lock();
- try
- {
- return this.callbacks.size() > 0;
- }
- finally
- {
- this.callbackRegistryLock.unlock();
- }
+ return this.callbacks.size() > 0;
}
/**
@@ -123,21 +110,13 @@
*/
public final NettyCallbackHandler getCallback(final String requestPath)
{
- this.callbackRegistryLock.lock();
- try
+ for (final NettyCallbackHandler handler : this.callbacks)
{
- for (final NettyCallbackHandler handler : this.callbacks)
+ if (handler.getPath().equals(requestPath))
{
- if (handler.getPath().equals(requestPath))
- {
- return handler;
- }
+ return handler;
}
}
- finally
- {
- this.callbackRegistryLock.unlock();
- }
return null;
}
@@ -149,16 +128,8 @@
*/
public final void registerCallback(final NettyCallbackHandler callback)
{
- this.callbackRegistryLock.lock();
- try
- {
- callback.init();
- this.callbacks.add(callback);
- }
- finally
- {
- this.callbackRegistryLock.unlock();
- }
+ callback.init();
+ this.callbacks.add(callback);
}
/**
@@ -168,16 +139,8 @@
*/
public final void unregisterCallback(final NettyCallbackHandler callback)
{
- this.callbackRegistryLock.lock();
- try
- {
- this.callbacks.remove(callback);
- callback.destroy();
- }
- finally
- {
- this.callbackRegistryLock.unlock();
- }
+ this.callbacks.remove(callback);
+ callback.destroy();
}
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java 2009-10-17
20:53:10 UTC (rev 10948)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java 2009-10-18
00:04:03 UTC (rev 10949)
@@ -55,9 +55,6 @@
/** Indicates server is stopped. */
private boolean stopped;
- /** Indicates server is terminated. */
- private boolean terminated;
-
/** Channel factory. */
private ChannelFactory channelFactory;
@@ -109,7 +106,7 @@
*
* @param callback new callback
*/
- public void registerCallback(final NettyCallbackHandler callback)
+ public synchronized void registerCallback(final NettyCallbackHandler callback)
{
if (callback != null)
{
@@ -123,7 +120,7 @@
*
* @param callback old callback
*/
- public void unregisterCallback(final NettyCallbackHandler callback)
+ public synchronized void unregisterCallback(final NettyCallbackHandler callback)
{
if (callback != null)
{
@@ -148,7 +145,7 @@
* @param requestPath request path
* @return callback handler associated with path
*/
- public NettyCallbackHandler getCallback(final String requestPath)
+ public synchronized NettyCallbackHandler getCallback(final String requestPath)
{
if (requestPath == null)
{
@@ -158,13 +155,13 @@
this.ensureUpAndRunning();
return this.nettyRequestHandler.getCallback(requestPath);
}
-
+
/**
* @see NettyHttpServer#hasMoreCallbacks()
*
* @return true if at least one callback handler is registered, false otherwise
*/
- public boolean hasMoreCallbacks()
+ public synchronized boolean hasMoreCallbacks()
{
this.ensureUpAndRunning();
return this.nettyRequestHandler.hasMoreCallbacks();
@@ -175,24 +172,13 @@
*
* @return server port
*/
- public int getPort()
+ public synchronized int getPort()
{
this.ensureUpAndRunning();
return this.port;
}
/**
- * Ensures server is up and running.
- */
- private synchronized void ensureUpAndRunning()
- {
- if (this.stopped)
- {
- throw new IllegalStateException("Server is down");
- }
- }
-
- /**
* Handles incomming connections.
*/
public synchronized void run()
@@ -208,20 +194,6 @@
ie.printStackTrace();
}
}
- try
- {
- //Close all connections and server sockets.
- NettyHttpServerImpl.NETTY_CHANNEL_GROUP.close().awaitUninterruptibly();
- //Shutdown the selector loop (boss and worker).
- if (this.channelFactory != null)
- {
- this.channelFactory.releaseExternalResources();
- }
- }
- finally
- {
- this.terminated = true;
- }
}
/**
@@ -229,26 +201,40 @@
*/
public synchronized void terminate()
{
- if (this.stopped)
+ synchronized (NettyHttpServerFactory.SERVERS)
{
- return;
- }
+ if (this.stopped)
+ {
+ return;
+ }
- this.stopped = true;
- while (!this.terminated)
- {
+ this.stopped = true;
+
try
{
- this.wait(NettyHttpServerImpl.WAIT_PERIOD);
+ //Close all connections and server sockets.
+ NettyHttpServerImpl.NETTY_CHANNEL_GROUP.close().awaitUninterruptibly();
+ //Shutdown the selector loop (boss and worker).
+ if (this.channelFactory != null)
+ {
+ this.channelFactory.releaseExternalResources();
+ }
}
- catch (InterruptedException ie)
+ finally
{
- ie.printStackTrace();
+ NettyHttpServerFactory.SERVERS.remove(this.port);
}
}
- synchronized (NettyHttpServerFactory.SERVERS)
+ }
+
+ /**
+ * Ensures server is up and running.
+ */
+ private void ensureUpAndRunning()
+ {
+ if (this.stopped)
{
- NettyHttpServerFactory.SERVERS.remove(this.port);
+ throw new IllegalStateException("Server is down");
}
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/RMClientSequence.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/RMClientSequence.java 2009-10-17
20:53:10 UTC (rev 10948)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/RMClientSequence.java 2009-10-18
00:04:03 UTC (rev 10949)
@@ -43,6 +43,9 @@
import org.jboss.logging.Logger;
import org.jboss.ws.core.jaxws.client.ClientImpl;
+import org.jboss.ws.core.server.netty.NettyCallbackHandler;
+import org.jboss.ws.core.server.netty.NettyHttpServer;
+import org.jboss.ws.core.server.netty.NettyHttpServerFactory;
import org.jboss.ws.extensions.addressing.AddressingClientUtil;
import org.jboss.ws.extensions.wsrm.config.RMConfig;
import org.jboss.ws.extensions.wsrm.api.RMException;
@@ -50,6 +53,7 @@
import org.jboss.ws.extensions.wsrm.protocol.RMProvider;
import org.jboss.ws.extensions.wsrm.protocol.spi.RMIncompleteSequenceBehavior;
import org.jboss.ws.extensions.wsrm.transport.RMUnassignedMessageListener;
+import org.jboss.ws.extensions.wsrm.transport.backchannel.RMRequestHandlerFactory;
import org.jboss.wsf.common.utils.UUIDGenerator;
/**
@@ -275,6 +279,15 @@
{
throw new RMException("Unable to terminate WSRM sequence", e);
}
+ finally
+ {
+ if (this.backPort != null)
+ {
+ NettyHttpServer server =
NettyHttpServerFactory.getNettyHttpServer(backPort.getPort(),
RMRequestHandlerFactory.getInstance());
+ NettyCallbackHandler callback = server.getCallback(this.backPort.getPath());
+ server.unregisterCallback(callback);
+ }
+ }
}
public final void sendCloseMessage()
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMCallbackHandlerFactory.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMCallbackHandlerFactory.java 2009-10-17
20:53:10 UTC (rev 10948)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMCallbackHandlerFactory.java 2009-10-18
00:04:03 UTC (rev 10949)
@@ -22,8 +22,6 @@
package org.jboss.ws.extensions.wsrm.transport.backchannel;
import java.net.URI;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
import org.jboss.ws.core.server.netty.NettyHttpServer;
import org.jboss.ws.core.server.netty.NettyHttpServerFactory;
@@ -37,9 +35,6 @@
*/
public final class RMCallbackHandlerFactory
{
- private static NettyHttpServer server;
- private static Lock lock = new ReentrantLock();
-
private RMCallbackHandlerFactory()
{
// no instances
@@ -47,25 +42,14 @@
public static RMCallbackHandler getCallbackHandler(URI backPort)
{
- lock.lock();
- try
+ NettyHttpServer server =
NettyHttpServerFactory.getNettyHttpServer(backPort.getPort(),
RMRequestHandlerFactory.getInstance());
+ RMCallbackHandler callbackHandler =
(RMCallbackHandler)server.getCallback(backPort.getPath());
+ if (callbackHandler == null)
{
- if (server == null)
- {
- server = NettyHttpServerFactory.getNettyHttpServer(backPort.getPort(),
RMRequestHandlerFactory.getInstance());
- }
- RMCallbackHandler callbackHandler =
(RMCallbackHandler)server.getCallback(backPort.getPath());
- if (callbackHandler == null)
- {
- callbackHandler = new RMCallbackHandlerImpl(backPort.getPath());
- server.registerCallback(callbackHandler);
- }
-
- return callbackHandler;
+ callbackHandler = new RMCallbackHandlerImpl(backPort.getPath());
+ server.registerCallback(callbackHandler);
}
- finally
- {
- lock.unlock();
- }
+
+ return callbackHandler;
}
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMRequestHandlerFactory.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMRequestHandlerFactory.java 2009-10-17
20:53:10 UTC (rev 10948)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/wsrm/transport/backchannel/RMRequestHandlerFactory.java 2009-10-18
00:04:03 UTC (rev 10949)
@@ -28,7 +28,7 @@
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
-final class RMRequestHandlerFactory implements
NettyRequestHandlerFactory<RMRequestHandlerImpl>
+public final class RMRequestHandlerFactory implements
NettyRequestHandlerFactory<RMRequestHandlerImpl>
{
private static final NettyRequestHandlerFactory<RMRequestHandlerImpl> SINGLETON
= new RMRequestHandlerFactory();