JBoss Remoting SVN: r5095 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-30 17:32:52 -0400 (Thu, 30 Apr 2009)
New Revision: 5095
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
Log:
JBREM-1112 (and others to be named): LeasePingerID, single ConnectionValidator per client invoker.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2009-04-30 21:32:26 UTC (rev 5094)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2009-04-30 21:32:52 UTC (rev 5095)
@@ -515,11 +515,8 @@
protected void cleanup()
{
- super.cleanup();
+// super.cleanup();
- if (controlMonitorTimerTask != null)
- controlMonitorTimerTask.shutdown();
-
synchronized (controlConnectionThreadMap)
{
Iterator it = controlConnectionThreadMap.values().iterator();
@@ -531,6 +528,11 @@
}
}
+ super.cleanup();
+
+ if (controlMonitorTimerTask != null)
+ controlMonitorTimerTask.shutdown();
+
if (secondaryServerSocketThread != null)
secondaryServerSocketThread.shutdown();
@@ -834,14 +836,18 @@
return;
}
-
+ if (!running)
+ {
+ return;
+ }
+
try
{
processInvocation(socket);
}
catch (Exception e)
{
- log.error("Unable to create new ServerThread: " + e.getMessage(), e);
+ log.error(BisocketServerInvoker.this + " Unable to create new ServerThread: " + e.getMessage(), e);
}
}
}
15 years, 8 months
JBoss Remoting SVN: r5094 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-30 17:32:26 -0400 (Thu, 30 Apr 2009)
New Revision: 5094
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionNotifier.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Remoting.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ServerInvoker.java
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java
Log:
JBREM-1112 (and others to be named): LeasePingerID, single ConnectionValidator per client invoker.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -49,6 +49,7 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.StreamCorruptedException;
+import java.lang.ref.WeakReference;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
import java.rmi.MarshalException;
@@ -152,6 +153,9 @@
public static final int DEFAULT_DISCONNECT_TIMEOUT = -1;
public static final String THROW_CALLBACK_EXCEPTION = "throwCallbackException";
+
+ private static Map connectionValidators = new HashMap();
+ private static Object connectionValidatorLock = new Object();
private static final Logger log = Logger.getLogger(Client.class);
@@ -175,6 +179,7 @@
private InvokerLocator locator;
private ConnectionValidator connectionValidator = null;
+ private ConnectionValidatorKey connectionValidatorKey;
private Map configuration = new HashMap();
private Map callbackConnectors = new HashMap();
@@ -187,6 +192,8 @@
private int disconnectTimeout = DEFAULT_DISCONNECT_TIMEOUT;
private boolean connected = false;
+
+ private Set connectionListeners = new HashSet();
// Constructors ---------------------------------------------------------------------------------
@@ -384,11 +391,54 @@
}
}
- if (connectionValidator == null)
+ synchronized (connectionValidatorLock)
{
- connectionValidator = new ConnectionValidator(this, metadata);
+ if (connectionValidator == null)
+ {
+ Map map = new HashMap(configuration);
+ map.putAll(metadata);
+ connectionValidatorKey = new ConnectionValidatorKey(invoker, map);
+ WeakReference ref = (WeakReference) connectionValidators.get(connectionValidatorKey);
+ if (ref == null)
+ {
+ connectionValidator = new ConnectionValidator(this, metadata);
+ connectionValidators.put(connectionValidatorKey, new WeakReference(connectionValidator));
+ connectionValidator.addConnectionListener(this, listener);
+ log.debug(this + ": created " + connectionValidator);
+ }
+ else
+ {
+ connectionValidator = (ConnectionValidator) ref.get();
+ if (connectionValidator.addConnectionListener(this, listener))
+ {
+ log.debug(this + ": reusing from static table: " + connectionValidator);
+ }
+ else
+ {
+ connectionValidator = new ConnectionValidator(this, metadata);
+ connectionValidators.put(connectionValidatorKey, new WeakReference(connectionValidator));
+ connectionValidator.addConnectionListener(this, listener);
+ log.debug(this + ": current ConnectionValidator is stopped: created " + connectionValidator);
+ }
+ }
+ }
+ else
+ {
+ if (connectionValidator.addConnectionListener(this, listener))
+ {
+ log.debug(this + ": reusing from local reference: " + connectionValidator);
+ }
+ else
+ {
+ connectionValidator = new ConnectionValidator(this, metadata);
+ connectionValidators.put(connectionValidatorKey, new WeakReference(connectionValidator));
+ connectionValidator.addConnectionListener(this, listener);
+ log.debug(this + ": current ConnectionValidator is stopped: created " + connectionValidator);
+ }
+ }
+
+ connectionListeners.add(listener);
}
- connectionValidator.addConnectionListener(listener);
}
/**
@@ -397,11 +447,29 @@
*/
public boolean removeConnectionListener(ConnectionListener listener)
{
- if (connectionValidator == null)
+ boolean isRemoved = false;
+ synchronized (connectionValidatorLock)
{
- return false;
+ if (connectionValidator == null)
+ {
+ return false;
+ }
+ isRemoved = connectionValidator.removeConnectionListener(this, listener);
+ if (connectionValidator.isStopped())
+ {
+ connectionValidators.remove(connectionValidatorKey);
+ log.debug(this + " removed from static map: " + connectionValidator);
+ connectionValidator = null;
+ connectionValidatorKey = null;
+ }
+ connectionListeners.remove(listener);
+ if (connectionListeners.isEmpty())
+ {
+ connectionValidator = null;
+ connectionValidatorKey = null;
+ }
}
- return connectionValidator.removeConnectionListener(listener);
+ return isRemoved;
}
/**
@@ -483,10 +551,25 @@
// this is a noop if no lease is active
invoker.terminateLease(sessionId, disconnectTimeout);
- if (connectionValidator != null)
+ synchronized (connectionValidatorLock)
{
- connectionValidator.stop();
+ if (connectionValidator != null)
+ {
+ Iterator it = connectionListeners.iterator();
+ while (it.hasNext())
+ {
+ ConnectionListener listener = (ConnectionListener) it.next();
+ connectionValidator.removeConnectionListener(this, listener);
+ }
+ if (connectionValidator.isStopped())
+ {
+ connectionValidators.remove(connectionValidatorKey);
+ log.debug(this + " removed from static map: " + connectionValidator);
+ }
+ }
+ // connectionValidator.stop();
connectionValidator = null;
+ connectionValidatorKey = null;
}
// Need to remove myself from registry so will not keep reference to me since I am of no
@@ -1537,6 +1620,7 @@
e.initCause(throwable);
throw e;
}
+ log.debug(this + " connected to " + locator);
}
else
{
@@ -1726,4 +1810,32 @@
// Inner classes --------------------------------------------------------------------------------
+
+ static class ConnectionValidatorKey
+ {
+ private ClientInvoker invoker;
+ private Map metadata;
+
+ ConnectionValidatorKey(ClientInvoker invoker, Map metadata)
+ {
+ this.invoker = invoker;
+ this.metadata = metadata;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (o == null)
+ return false;
+ if (! (o instanceof ConnectionValidatorKey))
+ return false;
+ ConnectionValidatorKey holder = (ConnectionValidatorKey) o;
+ boolean metadataEquals = (metadata == null && holder.metadata == null) || metadata.equals(holder.metadata);
+ return invoker == holder.invoker && metadataEquals;
+ }
+
+ public int hashCode()
+ {
+ return invoker.hashCode() * metadata.hashCode();
+ }
+ }
}
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionNotifier.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionNotifier.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionNotifier.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -43,7 +43,7 @@
{
try
{
- log.debug("Server connection lost to client (session id = " + clientSessionId);
+ log.debug(this + " Server connection lost to client (session id = " + clientSessionId);
Client client = new Client(new InvokerLocator(locatorurl), requestPayload);
client.setSessionId(clientSessionId);
@@ -52,7 +52,9 @@
Iterator it = listeners.iterator();
while (it.hasNext())
{
- ((ConnectionListener) it.next()).handleConnectionException(null, client);
+ ConnectionListener listener = (ConnectionListener) it.next();
+ listener.handleConnectionException(null, client);
+ log.debug("notified " + listener + " of connection lost to: " + clientSessionId);
}
}
}
@@ -66,9 +68,9 @@
{
try
{
- if(log.isTraceEnabled())
+// if(log.isTraceEnabled())
{
- log.trace("Client disconnected (session id = " + clientSessionId);
+ log.debug(this + " Client disconnected (session id = " + clientSessionId);
}
Client client = new Client(new InvokerLocator(locatorURL), requestPayload);
client.setSessionId(clientSessionId);
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -22,11 +22,11 @@
package org.jboss.remoting;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@@ -230,7 +230,7 @@
private Map metadata;
private InvokerLocator locator;
private Map configMap;
- private List listeners;
+ private Map listeners;
private ClientInvoker clientInvoker;
private Object lock = new Object();
private Object notificationLock = new Object();
@@ -243,6 +243,8 @@
private int failureDisconnectTimeout = -1;
private boolean isValid;
private Timer timer;
+ private MicroRemoteClientInvoker sharedInvoker;
+ private LeasePinger leasePinger;
// Constructors ---------------------------------------------------------------------------------
@@ -254,8 +256,9 @@
public ConnectionValidator(Client client, long pingPeriod)
{
this.client = client;
+ this.locator = client.getInvoker().getLocator();
this.pingPeriod = pingPeriod;
- listeners = new ArrayList();
+ listeners = new HashMap();
stopped = false;
getParameters(client, new HashMap());
log.debug(this + " created");
@@ -264,8 +267,9 @@
public ConnectionValidator(Client client, Map metadata)
{
this.client = client;
+ this.locator = client.getInvoker().getLocator();
pingPeriod = DEFAULT_PING_PERIOD;
- listeners = new ArrayList();
+ listeners = new HashMap();
stopped = false;
this.metadata = new HashMap(metadata);
getParameters(client, metadata);
@@ -367,36 +371,79 @@
// Public ---------------------------------------------------------------------------------------
- public void addConnectionListener(ConnectionListener listener)
+ public boolean addConnectionListener(Client client, ConnectionListener listener)
{
+ boolean doStart = false;
if (listener != null)
{
synchronized (lock)
{
+ if (stopped)
+ {
+ log.debug(this + " is stopped. Cannot add ConnectionListener: " + listener + " for " + client);
+ return false;
+ }
if (listeners.size() == 0)
{
- start();
+ doStart = true;
}
- listeners.add(listener);
+ Set s = (Set) listeners.get(listener);
+ if (s == null)
+ {
+ s = new HashSet();
+ }
+ s.add(client);
+ listeners.put(listener, s);
+ log.debug(this + " added ConnectionListener: " + listener + " for " + client);
}
+ if (doStart)
+ {
+ start();
+ }
}
+
+ return true;
}
- public boolean removeConnectionListener(ConnectionListener listener)
+ public boolean removeConnectionListener(Client client, ConnectionListener listener)
{
- boolean isRemoved = false;
- if (listener != null)
+ if (listener == null)
{
- synchronized (lock)
+ log.debug(this + " ConnectionListener is null");
+ return false;
+ }
+ synchronized (lock)
+ {
+ if (stopped)
{
- isRemoved = listeners.remove(listener);
- if (listeners.size() == 0)
- {
- stop();
- }
+ log.debug(this + " is stopped. It's too late to remove " + listener);
+ return false;
}
+ Set s = (Set) listeners.get(listener);
+ if (s == null)
+ {
+ log.debug(this + ": " + listener + " is not registered");
+ return false;
+ }
+ if (s.remove(client))
+ {
+ log.debug(this + " removed ConnectionListener: " + listener + " for " + client);
+ }
+ else
+ {
+ log.debug(this + ": " + listener + " is not registered for " + client);
+ return false;
+ }
+ if (s.size() == 0)
+ {
+ listeners.remove(listener);
+ }
+ if (listeners.size() == 0)
+ {
+ stop();
+ }
}
- return isRemoved;
+ return true;
}
public long getPingPeriod()
@@ -413,6 +460,11 @@
{
return "ConnectionValidator[" + Integer.toHexString(System.identityHashCode(this)) + ":" + clientInvoker + ", pingPeriod=" + pingPeriod + " ms]";
}
+
+ public boolean isStopped()
+ {
+ return stopped;
+ }
// Package protected ----------------------------------------------------------------------------
@@ -434,6 +486,14 @@
{
throw new RuntimeException("creating a ConnectionValidator on a local connection");
}
+ if (stopLeaseOnFailure)
+ {
+ sharedInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+ if (sharedInvoker != null)
+ {
+ leasePinger = sharedInvoker.getLeasePinger();
+ }
+ }
}
private void getParametersFromMap(Map config)
@@ -505,8 +565,17 @@
" to a boolean: must be a String");
}
}
-
+ ClientInvoker invoker = client.getInvoker();
+ if (invoker == null)
+ {
+ log.debug(this + " client invoker == null");
+ }
+ else
+ {
+ log.debug(this + " InvokerLocator: " + invoker.getLocator());
+ }
o = config.get(FAILURE_DISCONNECT_TIMEOUT);
+ log.debug(this + " \"failureDisconnectTimeout\" set to " + o);
if (o != null)
{
if (o instanceof String)
@@ -514,6 +583,7 @@
try
{
failureDisconnectTimeout = Integer.valueOf(((String) o)).intValue();
+ log.debug(this + " setting failureDisconnectTimeout to " + failureDisconnectTimeout);
}
catch (Exception e)
{
@@ -537,7 +607,6 @@
log.debug(this + " timeout: " + pingTimeout);
log.debug(this + " ping retries: " + configMap.get("NumberOfCallRetries"));
log.debug(this + " connection retries: " + configMap.get("NumberOfRetries"));
- locator = client.getInvoker().getLocator();
try
{
@@ -555,7 +624,14 @@
clientInvoker.connect();
}
+ try
+ {
TimerUtil.schedule(this, pingPeriod);
+ }
+ catch (Exception e)
+ {
+ log.error(this + " unable to schedule on TimerUtil", e);
+ }
started = true;
timer = new Timer(true);
log.debug(this + " started");
@@ -623,6 +699,7 @@
private boolean doStop()
{
+ log.debug("entering doStop()");
synchronized(lock)
{
if (stopped)
@@ -659,22 +736,33 @@
{
return;
}
- ListIterator itr = listeners.listIterator();
+ stopped = true;
+ log.debug(this + " is stopped. No more listeners will be accepted.");
+
+ Iterator itr = listeners.keySet().iterator();
while (itr.hasNext())
{
final ConnectionListener listener = (ConnectionListener) itr.next();
- new Thread()
+ Set clients = (Set) listeners.get(listener);
+ Iterator itr2 = clients.iterator();
+ while (itr2.hasNext())
{
- public void run()
+ final Client client = (Client) itr2.next();
+ new Thread()
{
- log.debug(this + " calling " + listener + ".handleConnectionException()");
- listener.handleConnectionException(t, client);
- }
- }.start();
+ public void run()
+ {
+ log.debug(this + " calling " + listener + ".handleConnectionException() for " + client);
+ listener.handleConnectionException(t, client);
+ }
+ }.start();
+ }
}
+
+ listeners.clear();
}
+
stop();
- listeners.clear();
}
// Inner classes --------------------------------------------------------------------------------
@@ -715,19 +803,23 @@
if (stopLeaseOnFailure)
{
- log.debug(this + " detected connection failure: stopping LeasePinger");
- MicroRemoteClientInvoker invoker = (MicroRemoteClientInvoker) client.getInvoker();
-
- if (invoker != null)
+ log.debug(ConnectionValidator.this + " detected connection failure: stopping LeasePinger");
+// MicroRemoteClientInvoker invoker = (MicroRemoteClientInvoker) client.getInvoker();
+//
+// if (invoker != null)
+// {
+ if (leasePinger == null)
{
+ leasePinger = sharedInvoker.getLeasePinger();
+ }
+ log.debug(ConnectionValidator.this + " shutting down lease pinger: " + leasePinger);
int disconnectTimeout = (failureDisconnectTimeout == -1) ? client.getDisconnectTimeout() : failureDisconnectTimeout;
- invoker.terminateLease(null, disconnectTimeout);
- log.debug(ConnectionValidator.this + " shut down lease pinger");
- }
- else
- {
- log.debug(ConnectionValidator.this + " unable to shut down lease pinger: client must have shut down");
- }
+ sharedInvoker.terminateLease(null, disconnectTimeout);
+// }
+// else
+// {
+// log.debug(ConnectionValidator.this + " unable to shut down lease pinger: " + leasePinger + ". Client must have shut down");
+// }
cancel();
}
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -25,6 +25,7 @@
import org.jboss.remoting.util.TimerUtil;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TimerTask;
@@ -48,6 +49,9 @@
private long leaseWindow = -1;
private long pingStart = -1;
private Map clientLeases = null;
+ private Object lock = new Object();
+ private String leasePingerId;
+ private boolean stopped;
private boolean leaseUpdated = false;
@@ -64,7 +68,9 @@
if(requestPayload != null)
{
this.requestPayload = (Map)requestPayload.get(ClientHolder.CLIENT_HOLDER_KEY);
+ this.leasePingerId = (String) requestPayload.get(LeasePinger.LEASE_PINGER_ID);
}
+ log.debug("leasePingerId: " + leasePingerId);
this.leaseWindow = leasePeriod * 2;
this.clientLeases = clientLeases;
}
@@ -72,9 +78,9 @@
public void startLease()
{
- if(isTraceEnabled)
+ if(true)
{
- log.trace("Starting lease for client invoker (session id = " + clientSessionId + ") with lease window time of " + leaseWindow);
+ log.debug("Starting lease for client invoker (session id = " + clientSessionId + ") with lease window time of " + leaseWindow);
}
leaseTimerTask = new LeaseTimerTask();
TimerUtil.schedule(leaseTimerTask, leaseWindow);
@@ -84,8 +90,28 @@
{
if(requestMap != null)
{
- this.requestPayload = (Map)requestMap.get(ClientHolder.CLIENT_HOLDER_KEY);
+ synchronized (lock)
+ {
+ this.requestPayload = (Map)requestMap.get(ClientHolder.CLIENT_HOLDER_KEY);
+
+ log.debug(this + " updating: new Client list:");
+ Collection clientHoldersCol = requestPayload.values();
+ Iterator itr = clientHoldersCol.iterator();
+ while (itr.hasNext())
+ {
+ Object val = itr.next();
+ if (val != null && val instanceof ClientHolder)
+ {
+ ClientHolder clientHolder = (ClientHolder) val;
+ log.debug(this + " " + clientHolder.getSessionId());
+ }
+ }
+ }
}
+ else
+ {
+ log.debug(this + " requestPayload == null");
+ }
updateLease(leasePeriod);
}
@@ -124,13 +150,14 @@
public void terminateLease(String sessionId)
{
- if(isTraceEnabled)
- {
- log.trace("Terminating lease for session id " + sessionId);
- }
// is this terminate for all clients
if (clientSessionId.equals(sessionId))
{
+ if(true)
+ {
+ log.debug(this + " Terminating lease group for session id " + sessionId);
+ }
+
stopLease();
// should be ok to call this will null as all the client should have
// already been disconnected and there been a notification for each
@@ -140,33 +167,101 @@
}
else
{
+ if(true)
+ {
+ log.debug(this + " Terminating individual lease for session id " + sessionId);
+ }
notifyClientTermination(sessionId);
}
}
-
+
+ public void terminateLeaseUponFailure(String sessionId)
+ {
+ // is this terminate for all clients
+ if (clientSessionId.equals(sessionId))
+ {
+ if(true)
+ {
+ log.debug(this + " Terminating lease group for session id " + sessionId);
+ }
+
+ stopLease();
+ // should be ok to call this will null as all the client should have
+ // already been disconnected and there been a notification for each
+ // of these client disconnections (which would remove the client from
+ // the lease, thus leaving the collection empty
+ notifyClientLost();
+ }
+ else
+ {
+ if(true)
+ {
+ log.warn(this + " Expected invoker session id: " + sessionId);
+ }
+ notifyClientLost();
+ }
+ }
+
+ public String toString()
+ {
+ String hash = Integer.toHexString(System.identityHashCode(this));
+ return "Lease[" + hash + ":" + clientSessionId + ":" + leasePingerId + "]";
+ }
+
private void notifyClientTermination(String sessionId)
{
- // is for a particular client, so need to inspect request payload for client
- if (requestPayload != null)
+ Map localRequestPayload = null;
+ synchronized (lock)
{
+ if (requestPayload != null)
+ {
+ localRequestPayload = new HashMap(requestPayload);
+ if (sessionId != null)
+ {
+ requestPayload.remove(sessionId);
+ }
+ }
+ }
+
+ if (localRequestPayload != null)
+ {
// should notify for one client or all?
if (sessionId != null)
{
- Object clientHolderObj = requestPayload.remove(sessionId);
+ synchronized (lock)
+ {
+ if (stopped)
+ {
+ log.debug(this + " already stopped");
+ return;
+ }
+ }
+
+ Object clientHolderObj = localRequestPayload.get(sessionId);
if (clientHolderObj != null && clientHolderObj instanceof ClientHolder)
{
ClientHolder clientHolder = (ClientHolder) clientHolderObj;
notifier.connectionTerminated(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
- if(isTraceEnabled)
+ if(true)
{
- log.trace("Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
+ log.debug(this + " Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
}
}
}
else
{
+ synchronized (lock)
+ {
+ if (stopped)
+ {
+ log.debug(this + " already stopped");
+ return;
+ }
+ stopped = true;
+ }
+
// loop through and notify for all clients
- Collection clientHoldersCol = requestPayload.values();
+ Collection clientHoldersCol = localRequestPayload.values();
if (clientHoldersCol != null && clientHoldersCol.size() > 0)
{
Iterator itr = clientHoldersCol.iterator();
@@ -177,9 +272,9 @@
{
ClientHolder clientHolder = (ClientHolder) val;
notifier.connectionTerminated(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
- if(isTraceEnabled)
+ if(true)
{
- log.trace("Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
+ log.debug(this + " Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
}
}
}
@@ -188,17 +283,32 @@
}
else
{
- log.warn("Tried to terminate lease for session id " + sessionId + ", but no collection of clients have been set.");
+ log.warn(this + " Tried to terminate lease for session id " + sessionId + ", but no collection of clients have been set.");
}
}
private void notifyClientLost()
{
- // is not for a particular client (but all clients associated with client invoker), so need to inspect request payload for client
- if (requestPayload != null)
+ Map localRequestPayload = null;
+ synchronized (lock)
{
+ if (stopped)
+ {
+ log.debug(this + " already stopped");
+ return;
+ }
+ stopped = true;
+ if (requestPayload != null)
+ {
+ localRequestPayload = new HashMap(requestPayload);
+ }
+ }
+
+ if (localRequestPayload != null)
+ {
// loop through and notify for all clients
- Collection clientHoldersCol = requestPayload.values();
+ Collection clientHoldersCol = localRequestPayload.values();
+ log.debug(this + " notifying listeners about " + clientHoldersCol.size() + " expired client(s)");
if (clientHoldersCol != null && clientHoldersCol.size() > 0)
{
Iterator itr = clientHoldersCol.iterator();
@@ -209,9 +319,9 @@
{
ClientHolder clientHolder = (ClientHolder) val;
notifier.connectionLost(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
- if(isTraceEnabled)
+ if(true)
{
- log.trace("Notified connection listener of lease expired due to lost connection from client (client session id = " + clientHolder.getSessionId());
+ log.debug(this + " Notified connection listener of lease expired due to lost connection from client (client session id = " + clientHolder.getSessionId());
}
}
}
@@ -219,11 +329,16 @@
}
else
{
- log.debug("requestPayload == null, calling ConnectionNotifier.connectionTerminated()");
- notifier.connectionTerminated(locatorURL, clientSessionId, null);
+ log.debug(this + " requestPayload == null, calling ConnectionNotifier.connectionLost()");
+ notifier.connectionLost(locatorURL, clientSessionId, null);
}
}
+ protected String getLeasePingerId()
+ {
+ return leasePingerId;
+ }
+
private void stopLease()
{
leaseTimerTask.cancel();
@@ -245,14 +360,14 @@
{
try
{
- if (log.isTraceEnabled()) log.trace("did not receive ping: " + clientSessionId);
+ if (true) log.debug(Lease.this + " did not receive ping: " + clientSessionId);
stopLease();
notifyClientLost();
if (clientLeases != null)
{
clientLeases.remove(clientSessionId);
}
- if (log.isTraceEnabled()) log.trace("removed lease:" + clientSessionId);
+ if (true) log.debug(Lease.this + " removed lease:" + clientSessionId);
}
catch (Throwable thr)
{
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -2,6 +2,7 @@
import org.jboss.logging.Logger;
import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.util.id.GUID;
import java.util.HashMap;
import java.util.Iterator;
@@ -25,6 +26,7 @@
public static final long DEFAULT_LEASE_PERIOD = 5000;
public static final int DEFAULT_DISCONNECT_TIMEOUT = -1;
+ public static final String LEASE_PINGER_ID = "leasePingerId";
// Static ---------------------------------------------------------------------------------------
@@ -44,6 +46,8 @@
private long pingPeriod = -1;
private int disconnectTimeout = DEFAULT_DISCONNECT_TIMEOUT;
+
+ private String leasePingerId;
// Constructors ---------------------------------------------------------------------------------
@@ -100,6 +104,24 @@
e.initCause(throwable);
throw e;
}
+
+// if (trace)
+ {
+ log.debug(this + " shut down");
+ if (!clients.isEmpty())
+ {
+ log.debug(this + " " + clients.size() + " remaining clients:");
+ Iterator it = clients.keySet().iterator();
+ while (it.hasNext())
+ {
+ log.debug(this + ": " + it.next());
+ }
+ }
+ else
+ {
+ log.debug(this + " No remaining clients");
+ }
+ }
}
}
@@ -138,7 +160,9 @@
if(trace) { log.trace(this + " removing client with session ID " + sessionID); }
- ClientHolder holder = (ClientHolder)clients.remove(sessionID);
+ // Don't remove holder until after client has been removed from server side Lease, to
+ // avoid a race with LeaseTimerTask sending a PING without the Client being removed.
+ ClientHolder holder = (ClientHolder)clients.get(sessionID);
if (holder != null)
{
@@ -166,11 +190,13 @@
log.warn(this + " failed sending disconnect for client lease for " +
"client with session ID " + sessionID);
}
+
+ clients.remove(sessionID);
}
else
{
- log.warn(this + " tried to remove lease for client with session ID " + sessionID +
- ", but no such lease was found");
+ log.debug(this + " tried to remove lease for client with session ID " + sessionID +
+ ", but no such lease was found: probably it was registered with an older LeasePinger");
}
if (clients.isEmpty())
@@ -233,7 +259,7 @@
public String toString()
{
- return "LeasePinger[" + invoker + "(" + invokerSessionID + ")]";
+ return "LeasePinger[" + leasePingerId + ":" + invoker + "(" + invokerSessionID + ")]";
}
// Package protected ----------------------------------------------------------------------------
@@ -252,6 +278,16 @@
log.debug(this + " setting disconnect timeout to: " + disconnectTimeout);
}
+ protected String getLeasePingerId()
+ {
+ return leasePingerId;
+ }
+
+ protected void setLeasePingerId(String leasePingerId)
+ {
+ this.leasePingerId = leasePingerId;
+ }
+
// Private --------------------------------------------------------------------------------------
private void sendClientPing()
@@ -277,10 +313,9 @@
Map clientsClone = new ConcurrentHashMap(clients);
Map requestClients = new ConcurrentHashMap();
requestClients.put(ClientHolder.CLIENT_HOLDER_KEY, clientsClone);
-
- InvocationRequest ir =
- new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
-
+ requestClients.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
+
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
invoker.invoke(ir);
if(trace) { log.trace(this + " successfully pinged the server"); }
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -345,6 +345,7 @@
if (sessionId == null)
{
+ log.debug(this + " shutting down LeasePinger: " + leasePinger);
// Independent of any particular Client - force LeasePinger shutdown.
// Should be called only if there is a reasonable belief that the lease
// has already stopped on the server side.
@@ -361,9 +362,11 @@
else
{
// Remove a particular Client.
+ log.debug(this + " removing client " + sessionId + " from LeasePinger: " + leasePinger);
boolean isLastClientLease = leasePinger.removeClient(sessionId);
if(isLastClientLease)
{
+ log.debug(this + " shutting down LeasePinger, " + sessionId + " was last client lease: " + leasePinger);
try
{
leasePinger.stopPing();
@@ -376,6 +379,10 @@
}
}
}
+ else
+ {
+ log.debug(this + " leasePinger is null: must have been shut down already");
+ }
}
}
@@ -413,8 +420,11 @@
// configuration should NOT be passed as want ping to be specific to client invoker
// and NOT to the client.
- InvocationRequest ir =
- new InvocationRequest(invokerSessionID, null, "$PING$", null, new HashMap(), null);
+ String leasePingerId = new GUID().toString();
+ Map requestMap = new HashMap();
+ requestMap.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
+ log.info(this + " initiating lease for leasePingerId " + leasePingerId);
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$", requestMap, new HashMap(), null);
Object ret = invoke(ir);
@@ -441,6 +451,7 @@
if(trace) { log.trace("server does have leasing enabled (with default lease period of " + defaultLeasePeriod + ") and will start a new lease pinger."); }
leasePinger = new LeasePinger(this, invokerSessionID, defaultLeasePeriod);
+ leasePinger.setLeasePingerId(leasePingerId);
leasePinger.addClient(clientSessionID, configuration, leasePeriod);
leasePinger.startPing();
}
@@ -579,4 +590,11 @@
super.finalize();
}
+ protected LeasePinger getLeasePinger()
+ {
+ synchronized(clientLeaseLock)
+ {
+ return leasePinger;
+ }
+ }
}
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Remoting.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Remoting.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -76,4 +76,12 @@
* org.jboss.remoting.ServerInvoker.InvalidStateException to an org.jboss.remoting.CannotConnectException.
*/
public static final String CHANGE_INVALID_STATE_TO_CANNOT_CONNECT = "changeInvalidStateToCannotConnect";
+
+ /**
+ * Flags indicating that connection monitoring should treat a connection as being defined
+ * by one or two of its endpoints. I.e., if a client invoker or server invoker stops and restarts, then
+ * all connections it participated in are now gone.
+ */
+ public static final String USE_CLIENT_CONNECTION_IDENTITY = "useClientConnectionIdentity";
+ public static final String USE_SERVER_CONNECTION_IDENTITY = "useServerConnectionIdentity";
}
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ServerInvoker.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ServerInvoker.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -262,6 +262,8 @@
protected ServerSocketFactory serverSocketFactory = null;
protected boolean registerCallbackListeners = true;
+
+ protected boolean useClientConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -702,6 +704,16 @@
return (ServerInvocationHandler) handlers.get(subsystem.toUpperCase());
}
+ protected boolean isUseClientConnectionIdentity()
+ {
+ return useClientConnectionIdentity;
+ }
+
+ protected void setUseClientConnectionIdentity(boolean useClientConnectionIdentity)
+ {
+ this.useClientConnectionIdentity = useClientConnectionIdentity;
+ }
+
public Object invoke(Object invoke) throws IOException
{
InvocationRequest request = null;
@@ -798,6 +810,7 @@
if ("$DISCONNECT$".equals(param))
{
+ log.debug(this + " got $DISCONNECT$");
if (leaseManagement)
{
terminateLease(invocation);
@@ -1177,6 +1190,13 @@
}
}
+ // config for useClientConnectionIdentity
+ String useClientConnectionIdentityString = (String)config.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if(useClientConnectionIdentityString != null)
+ {
+ useClientConnectionIdentity = Boolean.parseBoolean(useClientConnectionIdentityString);
+ }
+
// Inject ConnectionListener
String connectionListener = (String)config.get(CONNECTION_LISTENER);
if (connectionListener != null)
@@ -1694,6 +1714,7 @@
{
if (invocation != null)
{
+ // clientSessionId == MicroRemoteClientInvoker.invokerSessionID.
String clientSessionId = invocation.getSessionId();
Lease clientLease = (Lease)clientLeases.get(clientSessionId);
@@ -1711,9 +1732,9 @@
{
// just a client that disconnected, so only need to terminate lease for
// that particular client (by client session id).
- if (trace) log.trace("terminating client lease: " + clientSessionId);
ClientHolder holder = (ClientHolder) holderObj;
clientLease.terminateLease(holder.getSessionId());
+ if (true) log.debug("terminating client lease: " + clientSessionId + ":" + holder.getSessionId());
clientOnlyTerminated = true;
}
}
@@ -1721,7 +1742,7 @@
// now see if client invoker needs to be terminated
if (!clientOnlyTerminated)
{
- if (trace) log.trace("terminating invoker lease: " + clientSessionId);
+ if (true) log.debug("terminating invoker lease: " + clientLease);
clientLease.terminateLease(clientSessionId);
clientLeases.remove(clientSessionId);
}
@@ -1729,7 +1750,7 @@
else
{
String type = "invoker";
- Map reqMap = invocation.getRequestPayload();
+ Map reqMap = invocation.getRequestPayload();
if (reqMap != null)
{
Object holderObj = reqMap.get(ClientHolder.CLIENT_HOLDER_KEY);
@@ -1738,8 +1759,9 @@
type = "client";
}
}
- log.warn("Asked to terminate " + type + " lease for client session id " + clientSessionId +
- ", but lease for this id could not be found." + ": " + clientLeases);
+ log.debug("Asked to terminate " + type + " lease for invoker session id "
+ + clientSessionId + ", but lease for this id could not be found." +"" +
+ "Probably has been removed due to connection failure.");
}
}
}
@@ -1751,7 +1773,7 @@
String clientSessionId = invocation.getSessionId();
if(clientSessionId != null)
{
- if(trace) { log.trace("Getting lease for client session id: " + clientSessionId); }
+ if(trace) { log.trace("Getting lease for invoker session id: " + clientSessionId); }
Lease clientLease = (Lease)clientLeases.get(clientSessionId);
if(clientLease == null)
@@ -1764,15 +1786,48 @@
clientLeases.put(clientSessionId, newClientLease);
newClientLease.startLease();
-
- if(trace) { log.trace("No lease established for client session id (" + clientSessionId + "), so starting a new one."); }
+
+ if(true) { log.debug("No lease established for invoker session id (" + clientSessionId +
+ "), so starting a new one:" + newClientLease); }
}
else
{
- // including request payload from invocation as may contain updated list of clients.
- clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+ if (useClientConnectionIdentity)
+ {
+ String leasePingerId = (String) invocation.getRequestPayload().get(LeasePinger.LEASE_PINGER_ID);;
+ if (leasePingerId.equals(clientLease.getLeasePingerId()))
+ {
+ // including request payload from invocation as may contain updated list of clients.
+ log.debug(clientLease + " matches: leasePingerId: " + leasePingerId);
+ clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+ if(trace) { log.trace("Updated lease for invoker session id (" + clientSessionId + ")"); }
+ }
+ else
+ {
+ log.debug(clientLease + " does not match: leasePingerId: " + leasePingerId);
+ if (true) log.debug("terminating invoker lease: " + clientLease);
+ clientLease.terminateLeaseUponFailure(clientSessionId);
+ clientLeases.remove(clientSessionId);
- if(trace) { log.trace("Updated lease for client session id (" + clientSessionId + ")"); }
+ Lease newClientLease = new Lease(clientSessionId, leasePeriod,
+ locator.getLocatorURI(),
+ invocation.getRequestPayload(),
+ connectionNotifier,
+ clientLeases);
+
+ clientLeases.put(clientSessionId, newClientLease);
+ newClientLease.startLease();
+
+ if(true) { log.debug("starting a new lease:" + newClientLease); }
+ }
+ }
+ else
+ {
+ // including request payload from invocation as may contain updated list of clients.
+ clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+
+ if(trace) { log.trace("Updated lease for client session id (" + clientSessionId + ")"); }
+ }
}
}
}
@@ -1782,7 +1837,7 @@
{
if(leaseManagement && invokerSessionId != null)
{
- if(trace) { log.trace("Checking lease for client session id: " + invokerSessionId); }
+ if(trace) { log.trace("Checking lease for invoker session id: " + invokerSessionId); }
Lease clientLease = (Lease)clientLeases.get(invokerSessionId);
if(clientLease == null)
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java 2009-04-30 05:27:56 UTC (rev 5093)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java 2009-04-30 21:32:26 UTC (rev 5094)
@@ -32,7 +32,7 @@
public static final byte VERSION_2 = 2;
public static final byte VERSION_2_2 = 22;
- public static final String VERSION = "2.2.2.SP11";
+ public static final String VERSION = "2.2.2.SP11_JBREM-1112:042409";
private static final byte byteVersion = VERSION_2_2;
private static byte defaultByteVersion = byteVersion;
private static boolean performVersioning = true;
15 years, 8 months
JBoss Remoting SVN: r5093 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/connection.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-30 01:27:56 -0400 (Thu, 30 Apr 2009)
New Revision: 5093
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java
Log:
JBREM-1112: Removed test methods that depend on (non-existent) Client.USE_ALL_PARAMS.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java 2009-04-28 01:13:55 UTC (rev 5092)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java 2009-04-30 05:27:56 UTC (rev 5093)
@@ -216,89 +216,89 @@
}
- public void testZeroInvokerLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "/?" + Client.USE_ALL_PARAMS + "=true";
- clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=0";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, new HashMap());
-
- // Wait for broken connection and test.
- Thread.sleep(8000);
- assertTrue(serverConnectionListener.notified);
- assertNull(serverConnectionListener.throwable);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.removeConnectionListener(clientConnectionListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
+// public void testZeroInvokerLocator() throws Throwable
+// {
+// log.info("entering " + getName());
+//
+// // Start server.
+// setupServer();
+//
+// // Create client.
+// String clientLocatorURI = locatorURI;
+// clientLocatorURI += "/?" + Client.USE_ALL_PARAMS + "=true";
+// clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=0";
+// InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+// HashMap clientConfig = new HashMap();
+// clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+// clientConfig.put(Client.ENABLE_LEASE, "true");
+// addExtraClientConfig(clientConfig);
+// Client client = new Client(clientLocator, clientConfig);
+// client.connect();
+// log.info("client is connected");
+//
+// // Test connections.
+// assertEquals("abc", client.invoke("abc"));
+// log.info("connection is good");
+//
+// // Install ConnectionListener.
+// TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+// client.addConnectionListener(clientConnectionListener, new HashMap());
+//
+// // Wait for broken connection and test.
+// Thread.sleep(8000);
+// assertTrue(serverConnectionListener.notified);
+// assertNull(serverConnectionListener.throwable);
+// assertTrue(clientConnectionListener.notified);
+// assertTrue(clientConnectionListener.throwable instanceof Exception);
+// assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+//
+// client.removeConnectionListener(clientConnectionListener);
+// client.disconnect();
+// shutdownServer();
+// log.info(getName() + " PASSES");
+// }
- public void testNonZeroInvokerLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "/?" + Client.USE_ALL_PARAMS + "=true";
- clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=10000";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, new HashMap());
-
- // Wait for broken connection and test.
- Thread.sleep(4000);
- assertTrue(serverConnectionListener.notified);
- assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
+// public void testNonZeroInvokerLocator() throws Throwable
+// {
+// log.info("entering " + getName());
+//
+// // Start server.
+// setupServer();
+//
+// // Create client.
+// String clientLocatorURI = locatorURI;
+// clientLocatorURI += "/?" + Client.USE_ALL_PARAMS + "=true";
+// clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=10000";
+// InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+// HashMap clientConfig = new HashMap();
+// clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+// clientConfig.put(Client.ENABLE_LEASE, "true");
+// addExtraClientConfig(clientConfig);
+// Client client = new Client(clientLocator, clientConfig);
+// client.connect();
+// log.info("client is connected");
+//
+// // Test connections.
+// assertEquals("abc", client.invoke("abc"));
+// log.info("connection is good");
+//
+// // Install ConnectionListener.
+// TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+// client.addConnectionListener(clientConnectionListener, new HashMap());
+//
+// // Wait for broken connection and test.
+// Thread.sleep(4000);
+// assertTrue(serverConnectionListener.notified);
+// assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
+// assertTrue(clientConnectionListener.notified);
+// assertTrue(clientConnectionListener.throwable instanceof Exception);
+// assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+//
+// client.disconnect();
+// shutdownServer();
+// log.info(getName() + " PASSES");
+// }
public void testZeroConfig() throws Throwable
15 years, 8 months
JBoss Remoting SVN: r5092 - in remoting3/trunk: taglet and 7 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-04-27 21:13:55 -0400 (Mon, 27 Apr 2009)
New Revision: 5092
Added:
remoting3/trunk/taglet/
remoting3/trunk/taglet/pom.xml
remoting3/trunk/taglet/src/
remoting3/trunk/taglet/src/main/
remoting3/trunk/taglet/src/main/java/
remoting3/trunk/taglet/src/main/java/org/
remoting3/trunk/taglet/src/main/java/org/jboss/
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingConsumeTaglet.java
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingImplementTaglet.java
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingInternalTaglet.java
remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java
Log:
Add remoting API description taglet
Added: remoting3/trunk/taglet/pom.xml
===================================================================
--- remoting3/trunk/taglet/pom.xml (rev 0)
+++ remoting3/trunk/taglet/pom.xml 2009-04-28 01:13:55 UTC (rev 5092)
@@ -0,0 +1,56 @@
+<!--
+ ~ JBoss, Home of Professional Open Source
+ ~ Copyright 2009, JBoss Inc., and individual contributors as indicated
+ ~ by the @authors tag. See the copyright.txt in the distribution for a
+ ~ full listing of individual contributors.
+ ~
+ ~ This is free software; you can redistribute it and/or modify it
+ ~ under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ This software is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this software; if not, write to the Free
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jboss.remoting</groupId>
+ <artifactId>jboss-remoting-taglet</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1.0.CR1</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.sun</groupId>
+ <artifactId>tools</artifactId>
+ <version>1.5.0</version>
+ <scope>system</scope>
+ <systemPath>${java.home}/../lib/tools.jar</systemPath>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingConsumeTaglet.java
===================================================================
--- remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingConsumeTaglet.java (rev 0)
+++ remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingConsumeTaglet.java 2009-04-28 01:13:55 UTC (rev 5092)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.taglet;
+
+import com.sun.javadoc.Tag;
+
+public final class RemotingConsumeTaglet extends RemotingTypeTaglet {
+
+ public String getName() {
+ return "remoting.consume";
+ }
+
+ public String toString(final Tag tag) {
+ String t = tag.holder().isInterface() ? "interface" : tag.holder().isClass() ? "class" : "type";
+ return "<p>This " + t + " is part of the Remoting 3 public API. While instances of this type may " +
+ "be used publicly, users are not encouraged to implement or extend this type as members may be " +
+ "added without notice.\n";
+ }
+}
Added: remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingImplementTaglet.java
===================================================================
--- remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingImplementTaglet.java (rev 0)
+++ remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingImplementTaglet.java 2009-04-28 01:13:55 UTC (rev 5092)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.taglet;
+
+import com.sun.javadoc.Tag;
+
+public final class RemotingImplementTaglet extends RemotingTypeTaglet {
+
+ public String getName() {
+ return "remoting.implement";
+ }
+
+ public String toString(final Tag tag) {
+ final boolean isinterface = tag.holder().isInterface();
+ String t = isinterface ? "interface" : tag.holder().isClass() ? "class" : "type";
+ String e = isinterface ? "implemented" : "extended";
+ return "<p>This " + t + " is part of the Remoting 3 public API, and is intended to be " + e + " by " +
+ "users of this API. Abstract members will generally not be added to such types so as to avoid " +
+ "backwards compatibility problems.\n";
+ }
+}
Added: remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingInternalTaglet.java
===================================================================
--- remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingInternalTaglet.java (rev 0)
+++ remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingInternalTaglet.java 2009-04-28 01:13:55 UTC (rev 5092)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.taglet;
+
+import com.sun.javadoc.Tag;
+
+public final class RemotingInternalTaglet extends RemotingTypeTaglet {
+
+ public String getName() {
+ return "remoting.internal";
+ }
+
+ public String toString(final Tag tag) {
+ String t = tag.holder().isInterface() ? "interface" : tag.holder().isClass() ? "class" : "type";
+ return "<p><b>Internal Class</b> - this " + t + " is part of the internal Remoting 3 implementation and is " +
+ "<b>not</b> intended to be used or consumed publicly. Members of this class may be added, removed, " +
+ "and/or changed without notice.\n";
+ }
+}
Added: remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java
===================================================================
--- remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java (rev 0)
+++ remoting3/trunk/taglet/src/main/java/org/jboss/remoting3/taglet/RemotingTypeTaglet.java 2009-04-28 01:13:55 UTC (rev 5092)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.taglet;
+
+import java.util.Map;
+
+import com.sun.javadoc.Tag;
+import com.sun.tools.doclets.Taglet;
+
+public abstract class RemotingTypeTaglet implements Taglet {
+
+ public boolean inField() {
+ return false;
+ }
+
+ public boolean inConstructor() {
+ return false;
+ }
+
+ public boolean inMethod() {
+ return false;
+ }
+
+ public boolean inOverview() {
+ return false;
+ }
+
+ public boolean inPackage() {
+ return false;
+ }
+
+ public boolean inType() {
+ return true;
+ }
+
+ public boolean isInlineTag() {
+ return false;
+ }
+
+ public String toString(final Tag[] tags) {
+ return tags.length > 0 ? toString(tags[0]) : "";
+ }
+
+ private static void add(Map<String, Taglet> tagletMap, Taglet taglet) {
+ tagletMap.put(taglet.getName(), taglet);
+ }
+
+ public static void register(Map<String, Taglet> tagletMap) {
+ add(tagletMap, new RemotingConsumeTaglet());
+ add(tagletMap, new RemotingImplementTaglet());
+ add(tagletMap, new RemotingInternalTaglet());
+ }
+}
15 years, 8 months
JBoss Remoting SVN: r5091 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-23 02:28:22 -0400 (Thu, 23 Apr 2009)
New Revision: 5091
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java
Log:
JBREM-1120: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java 2009-04-23 06:28:22 UTC (rev 5091)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.ssl.timeout;
+
+import org.jboss.test.remoting.transport.socket.timeout.SSLWriteTimeoutTestParent;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class SSLSocketWriteTimeoutTestCase extends SSLWriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+}
15 years, 8 months
JBoss Remoting SVN: r5090 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-23 02:27:42 -0400 (Thu, 23 Apr 2009)
New Revision: 5090
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
Log:
JBREM-1120: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java 2009-04-23 06:27:42 UTC (rev 5090)
@@ -0,0 +1,480 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.timeout;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+import javax.net.ssl.HandshakeCompletedListener;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationFailureException;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.security.SSLSocketBuilder;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+import org.jboss.test.remoting.transport.socket.timeout.WriteTimeoutTestParent.TestServerSocketFactory;
+import org.jboss.test.remoting.transport.socket.timeout.WriteTimeoutTestParent.TestSocketFactory;
+
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public abstract class SSLWriteTimeoutTestParent extends WriteTimeoutTestParent
+{
+ private static Logger log = Logger.getLogger(SSLWriteTimeoutTestParent.class);
+
+ private static boolean firstTime = true;
+
+ protected static int SECONDARY_SERVER_SOCKET_PORT = 8765;
+ protected static String SECONDARY_SERVER_SOCKET_PORT_STRING = "8765";
+ protected static boolean callbackTest;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ String keyStoreFilePath = getClass().getResource("../.keystore").getFile();
+ System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
+ System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
+ String trustStoreFilePath = getClass().getResource("../.truststore").getFile();
+ System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
+ }
+ super.setUp();
+ }
+
+
+ protected String getServerSocketFactoryClassName()
+ {
+ return SSLTestServerSocketFactory.class.getName();
+ }
+
+ protected Constructor getServerSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return SSLTestServerSocketFactory.class.getConstructor(new Class[]{int.class});
+ }
+
+ protected String getSocketFactoryClassName()
+ {
+ return SSLTestSocketFactory.class.getName();
+ }
+
+ protected Constructor getSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return SSLTestSocketFactory.class.getConstructor(new Class[]{int.class});
+ }
+
+ static public class SSLTestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ ServerSocketFactory factory;
+
+ public SSLTestServerSocketFactory() throws IOException
+ {
+ this.timeout = 5000;
+ setupFactory();
+ }
+ public SSLTestServerSocketFactory(int timeout) throws IOException
+ {
+ this.timeout = timeout;
+ setupFactory();
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket();
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(timeout, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != SECONDARY_SERVER_SOCKET_PORT)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, timeout, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != SECONDARY_SERVER_SOCKET_PORT)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, timeout, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != SECONDARY_SERVER_SOCKET_PORT)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, ifAddress, timeout, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLServerSocketFactory();
+ }
+ }
+
+
+ static class SSLTestServerSocket extends SSLServerSocket
+ {
+ int timeout;
+ SSLServerSocket serverSocket;
+
+ public SSLTestServerSocket(int timeout, SSLServerSocket serverSocket) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.serverSocket = serverSocket;
+ }
+ public SSLTestServerSocket(int port, int timeout, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.serverSocket = serverSocket;
+ }
+ public SSLTestServerSocket(int port, int backlog, int timeout, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.serverSocket = serverSocket;
+ }
+ public SSLTestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.serverSocket = serverSocket;
+ }
+ public Socket accept() throws IOException
+ {
+ SSLSocket s1 = (SSLSocket) serverSocket.accept();
+ Socket s2 = new SSLTestSocket(timeout, s1);
+ implAccept(s2);
+ return s2;
+ }
+ public String toString()
+ {
+ return "SSLTestServerSocket[" + serverSocket.toString() + "]";
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return serverSocket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return serverSocket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return serverSocket.getEnabledProtocols();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return serverSocket.getNeedClientAuth();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return serverSocket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return serverSocket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return serverSocket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return serverSocket.getWantClientAuth();
+ }
+ public void setEnableSessionCreation(boolean arg0)
+ {
+ serverSocket.setEnableSessionCreation(arg0);
+ }
+ public void setEnabledCipherSuites(String[] arg0)
+ {
+ serverSocket.setEnabledCipherSuites(arg0);
+ }
+ public void setEnabledProtocols(String[] arg0)
+ {
+ serverSocket.setEnabledProtocols(arg0);
+ }
+ public void setNeedClientAuth(boolean arg0)
+ {
+ serverSocket.setNeedClientAuth(arg0);
+ }
+ public void setUseClientMode(boolean arg0)
+ {
+ serverSocket.setUseClientMode(arg0);
+ }
+ public void setWantClientAuth(boolean arg0)
+ {
+ serverSocket.setWantClientAuth(arg0);
+ }
+ }
+
+
+ public static class SSLTestSocketFactory extends SocketFactory
+ {
+ int timeout;
+ SocketFactory factory;
+
+ public SSLTestSocketFactory() throws IOException
+ {
+ timeout = 5000;
+ setupFactory();
+ }
+ public SSLTestSocketFactory(int timeout) throws IOException
+ {
+ this.timeout = timeout;
+ setupFactory();
+ }
+ public Socket createSocket() throws IOException
+ {
+ return new SSLTestSocket(timeout, ((SSLSocket) factory.createSocket()));
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ return new SSLTestSocket(arg0, arg1, timeout, ((SSLSocket) factory.createSocket()));
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ return new SSLTestSocket(arg0, arg1, timeout, ((SSLSocket) factory.createSocket()));
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ return new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, ((SSLSocket) factory.createSocket()));
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ return new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, ((SSLSocket) factory.createSocket()));
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLSocketFactory();
+ }
+ }
+
+ static class SSLTestSocket extends SSLSocket
+ {
+ int timeout;
+ SSLSocket socket;
+
+ public SSLTestSocket(int timeout, SSLSocket socket)
+ {
+ this.timeout = timeout;
+ this.socket = socket;
+ }
+ public SSLTestSocket(String host, int port, int timeout, SSLSocket socket) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.socket = socket;
+ }
+ public SSLTestSocket(InetAddress address, int port, int timeout, SSLSocket socket) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.socket = socket;
+ }
+ public SSLTestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, SSLSocket socket) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.socket = socket;
+ }
+ public SSLTestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, SSLSocket socket) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.socket = socket;
+ }
+ public String toString()
+ {
+ return "SSLTestSocket[" + socket.toString() + "]";
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(socket.getOutputStream(), timeout);
+ }
+ public void addHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.addHandshakeCompletedListener(listener);
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return socket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return socket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return socket.getEnabledProtocols();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return socket.getNeedClientAuth();
+ }
+ public SSLSession getSession()
+ {
+ return socket.getSession();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return socket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return socket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return socket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return socket.getWantClientAuth();
+ }
+ public void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.removeHandshakeCompletedListener(listener);
+ }
+ public void setEnableSessionCreation(boolean flag)
+ {
+ socket.setEnableSessionCreation(flag);
+ }
+ public void setEnabledCipherSuites(String[] suites)
+ {
+ socket.setEnabledCipherSuites(suites);
+ }
+ public void setEnabledProtocols(String[] protocols)
+ {
+ socket.setEnabledProtocols(protocols);
+ }
+ public void setNeedClientAuth(boolean need)
+ {
+ socket.setNeedClientAuth(need);
+ }
+ public void setUseClientMode(boolean mode)
+ {
+ socket.setUseClientMode(mode);
+ }
+ public void setWantClientAuth(boolean want)
+ {
+ socket.setWantClientAuth(want);
+ }
+ public void startHandshake() throws IOException
+ {
+ socket.startHandshake();
+ }
+ }
+}
\ No newline at end of file
15 years, 8 months
JBoss Remoting SVN: r5089 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 23:43:14 -0400 (Wed, 22 Apr 2009)
New Revision: 5089
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
Log:
JBREM-1120: Reduced log level.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2009-04-23 03:39:13 UTC (rev 5088)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2009-04-23 03:43:14 UTC (rev 5089)
@@ -91,7 +91,7 @@
if (firstTime)
{
firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE);
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
PatternLayout layout = new PatternLayout(pattern);
15 years, 8 months
JBoss Remoting SVN: r5088 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 23:39:13 -0400 (Wed, 22 Apr 2009)
New Revision: 5088
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
Log:
JBREM-1120: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java 2009-04-23 03:39:13 UTC (rev 5088)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.timeout;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class SocketWriteTimeoutTestCase extends WriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "socket";
+ }
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2009-04-23 03:39:13 UTC (rev 5088)
@@ -0,0 +1,652 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.timeout;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationFailureException;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public abstract class WriteTimeoutTestParent extends TestCase
+{
+ private static Logger log = Logger.getLogger(WriteTimeoutTestParent.class);
+
+ private static boolean firstTime = true;
+
+ protected static int SECONDARY_SERVER_SOCKET_PORT = 8765;
+ protected static String SECONDARY_SERVER_SOCKET_PORT_STRING = "8765";
+ protected static boolean callbackTest;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testClientWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, false, "", -1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(5000));
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+
+ // Test client side write timeout.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (InvocationFailureException e)
+ {
+ log.info(e.getMessage());
+ assertNotNull(e.getMessage());
+ assertTrue(e.getMessage().startsWith("Unable to perform invocation"));
+ assertTrue(e.getCause() instanceof IOException);
+ IOException ioe = (IOException) e.getCause();
+ assertEquals("closed", ioe.getMessage());
+ log.info("got expected Exception");
+ }
+ catch (Throwable t)
+ {
+ log.error("got unexpected Exception", t);
+ fail("got unexpected Exception");
+ }
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testServerWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, false, "1000", 5000);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("numberOfCallRetries", "1");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+
+ // Test server side write timeout.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (InvocationFailureException e)
+ {
+ log.info(e.getMessage());
+ assertNotNull(e.getMessage());
+ assertTrue(e.getMessage().startsWith("Unable to perform invocation"));
+ assertTrue(e.getCause() instanceof EOFException);
+ log.info("got expected Exception");
+ }
+ catch (Throwable t)
+ {
+ log.error("got unexpected Exception", t);
+ fail("got unexpected Exception");
+ }
+
+ // Test server invoker state.
+ Thread.sleep(4000);
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
+ assertEquals(0, serverInvoker.getCurrentClientPoolSize());
+ assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
+ log.info("used ServerThread has returned to threadPool");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testClientCallbackWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, false, "", -1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Test client callback write timeout.
+ log.info("registering callback handler");
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ if (isBisocket(getTransport()))
+ {
+ metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ metadata.put(Remoting.SOCKET_FACTORY_NAME, TestSocketFactory.class.getName());
+ metadata.put("numberOfCallRetries", "1");
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ metadata.put(Bisocket.PING_FREQUENCY, "11111111");
+ }
+ else
+ {
+ metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ metadata.put(ServerInvoker.SERVER_SOCKET_FACTORY, TestServerSocketFactory.class.getName());
+ metadata.put("numberOfCallRetries", "1");
+ }
+ client.addListener(callbackHandler, metadata, null, true);
+
+ // Test server invoker state.
+ Thread.sleep(4000);
+ Set callbackConnectors = client.getCallbackConnectors(callbackHandler);
+ assertEquals(1, callbackConnectors.size());
+ Connector callbackConnector = (Connector) callbackConnectors.iterator().next();
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) callbackConnector.getServerInvoker();
+ assertEquals(0, serverInvoker.getCurrentClientPoolSize());
+ assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
+ log.info("used ServerThread has returned to threadPool");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testServerCallbackWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ if (isBisocket(getTransport()))
+ {
+ callbackTest = true;
+ setupServer(true, false, "1000", 5000);
+ }
+ else
+ {
+ setupServer(false, true, "1000", 5000);
+ }
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("numberOfCallRetries", "1");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Test server callback write timeout.
+ log.info("registering callback handler");
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+ HashMap metadata = new HashMap();
+ if (isBisocket(getTransport()))
+ {
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ }
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, null, null, true);
+
+ // Test server invoker state.
+ Thread.sleep(4000);
+ Throwable t = invocationHandler.t;
+ assertTrue(t instanceof HandleCallbackException);
+ assertTrue(t.getCause() instanceof InvocationFailureException);
+ InvocationFailureException e = (InvocationFailureException) t.getCause();
+ assertNotNull(e.getMessage());
+ assertTrue(e.getMessage().startsWith("Unable to perform invocation"));
+ assertTrue(e.getCause() instanceof IOException);
+ IOException ioe = (IOException) e.getCause();
+ assertEquals("closed", ioe.getMessage());
+ log.info("got expected Exception");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected abstract String getTransport();
+
+ protected boolean isBisocket(String transport)
+ {
+ return transport.indexOf("bisocket") >= 0;
+ }
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean setWriteTimeout, boolean setCallbackWriteTimeout,
+ String writeTimeout, int blockingTime) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ if (isBisocket(getTransport()))
+ {
+ config.put(Bisocket.SECONDARY_BIND_PORT, SECONDARY_SERVER_SOCKET_PORT_STRING);
+ config.put(Bisocket.PING_FREQUENCY, "11111111");
+ }
+ if (setWriteTimeout)
+ {
+ config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
+ config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, new TestServerSocketFactory(blockingTime));
+ }
+ if (setCallbackWriteTimeout)
+ {
+ config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
+ config.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(blockingTime));
+ }
+ if (callbackTest)
+ {
+ config.put("numberOfCallRetries", "1");
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ Throwable t;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ try
+ {
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ catch (Throwable t)
+ {
+ this.t = t;
+ }
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+
+
+ static public class TestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ public TestServerSocketFactory()
+ {
+ this.timeout = 5000;
+ }
+ public TestServerSocketFactory(int timeout)
+ {
+ this.timeout = timeout;
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket();
+ }
+ else
+ {
+ ss = new TestServerSocket(timeout);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != SECONDARY_SERVER_SOCKET_PORT)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, timeout);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != SECONDARY_SERVER_SOCKET_PORT)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, timeout);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != SECONDARY_SERVER_SOCKET_PORT)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, ifAddress, timeout);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ }
+
+
+ static class TestServerSocket extends ServerSocket
+ {
+ int timeout;
+
+ public TestServerSocket(int timeout) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ }
+ public TestServerSocket(int port, int timeout) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ }
+ public TestServerSocket(int port, int backlog, int timeout) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ }
+ public TestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ }
+ public Socket accept() throws IOException
+ {
+ Socket s = new TestSocket(timeout);
+ implAccept(s);
+ return s;
+ }
+ public String toString()
+ {
+ return "TestServerSocket[" + getLocalPort() + "]";
+ }
+ }
+
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ int timeout;
+
+ public TestSocketFactory()
+ {
+ timeout = 5000;
+ }
+ public TestSocketFactory(int timeout)
+ {
+ this.timeout = timeout;
+ }
+ public Socket createSocket()
+ {
+ return new TestSocket(timeout);
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ return new TestSocket(arg0, arg1, timeout);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ return new TestSocket(arg0, arg1, timeout);
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ return new TestSocket(arg0, arg1, arg2, arg3, timeout);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ return new TestSocket(arg0, arg1, arg2, arg3, timeout);
+ }
+ }
+
+ static class TestSocket extends Socket
+ {
+ int timeout;
+
+ public TestSocket(int timeout)
+ {
+ this.timeout = timeout;
+ }
+ public TestSocket(String host, int port, int timeout) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ }
+ public TestSocket(InetAddress address, int port, int timeout) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ }
+ public TestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ }
+ public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(super.getOutputStream(), timeout);
+ }
+ }
+
+ static class TestOutputStream extends OutputStream
+ {
+ OutputStream os;
+ int timeout;
+ boolean closed;
+
+ public TestOutputStream(OutputStream os, int timeout)
+ {
+ this.os = os;
+ this.timeout = timeout;
+ }
+ public void close()throws IOException
+ {
+ closed = true;
+ super.close();
+ log.info("closed");
+ }
+ public void write(int b) throws IOException
+ {
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ try
+ {
+ log.info("TestOutputStream.write() sleeping: " + timeout);
+ Thread.sleep(timeout);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ log.info("TestOutputStream writing");
+ os.write(b, off, len);
+ }
+ }
+}
\ No newline at end of file
15 years, 8 months
JBoss Remoting SVN: r5087 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 23:38:30 -0400 (Wed, 22 Apr 2009)
New Revision: 5087
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java
Log:
JBREM-1120: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java 2009-04-23 03:38:30 UTC (rev 5087)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.bisocket.timeout;
+
+import org.jboss.test.remoting.transport.socket.timeout.WriteTimeoutTestParent;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class BisocketWriteTimeoutTestCase extends WriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+}
15 years, 8 months
JBoss Remoting SVN: r5086 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 23:37:32 -0400 (Wed, 22 Apr 2009)
New Revision: 5086
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
Log:
JBREM-1120: Added some logging.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java 2009-04-23 03:36:18 UTC (rev 5085)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java 2009-04-23 03:37:32 UTC (rev 5086)
@@ -38,12 +38,13 @@
{
timerTask = new OutputTimerTask(this);
timer.schedule(timerTask, outputTimeout);
+ if (log.isTraceEnabled()) log.trace("scheduled OutputTimerTask: " + outputTimeout);
}
catch (IllegalStateException e)
{
timer = new Timer("TimedOutputStreamTimer", true);
timer.schedule(new OutputTimerTask(this), outputTimeout);
- log.info("scheduled OutputTimerTask: " + outputTimeout);
+ if (log.isTraceEnabled()) log.trace("scheduled OutputTimerTask: " + outputTimeout);
}
}
}
@@ -72,11 +73,13 @@
{
timerTask = new OutputTimerTask(this);
timer.schedule(timerTask, outputTimeout);
+ if (log.isTraceEnabled()) log.trace("scheduled OutputTimerTask: " + outputTimeout);
}
catch (IllegalStateException e)
{
timer = new Timer("TimedOutputStreamTimer", true);
- timer.schedule(new OutputTimerTask(this), outputTimeout);
+ timer.schedule(new OutputTimerTask(this), outputTimeout);
+ if (log.isTraceEnabled()) log.trace("scheduled OutputTimerTask: " + outputTimeout);
}
}
}
15 years, 8 months