[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...
Ron Sigal
ron_sigal at yahoo.com
Mon Aug 20 02:06:28 EDT 2007
User: rsigal
Date: 07/08/20 02:06:28
Modified: src/main/org/jboss/remoting Tag:
remoting_2_2_2_experimental
MicroRemoteClientInvoker.java
Log:
JBREM-783: Reverted to version before changes made for JBREM-783.
Revision Changes Path
No revision
No revision
1.7.2.14.4.5.2.2 +24 -166 JBossRemoting/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MicroRemoteClientInvoker.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java,v
retrieving revision 1.7.2.14.4.5.2.1
retrieving revision 1.7.2.14.4.5.2.2
diff -u -b -r1.7.2.14.4.5.2.1 -r1.7.2.14.4.5.2.2
--- MicroRemoteClientInvoker.java 18 Aug 2007 01:05:19 -0000 1.7.2.14.4.5.2.1
+++ MicroRemoteClientInvoker.java 20 Aug 2007 06:06:28 -0000 1.7.2.14.4.5.2.2
@@ -27,12 +27,11 @@
*
* @author <a href="mailto:jhaynie at vocalocity.net">Jeff Haynie</a>
* @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
- * @version $Revision: 1.7.2.14.4.5.2.1 $
+ * @version $Revision: 1.7.2.14.4.5.2.2 $
*/
public abstract class MicroRemoteClientInvoker extends AbstractInvoker implements ClientInvoker
{
private static final Logger log = Logger.getLogger(MicroRemoteClientInvoker.class);
- private static int leaseCounter;
private boolean trace = log.isTraceEnabled();
protected boolean connected = false;
@@ -42,7 +41,6 @@
private final Object clientLeaseLock = new Object();
private LeasePinger leasePinger = null;
private String invokerSessionID = new GUID().toString();
- private Exception leasePingerException;
public MicroRemoteClientInvoker(InvokerLocator locator)
{
@@ -313,56 +311,25 @@
public void terminateLease(String sessionId, int disconnectTimeout)
{
- // The synchronization of establishLease() and terminateLease() has been
- // reorganized - see JBREM-783.
-
- // The process of removing an org.jboss.remoting.Client from a LeasePinger
- // is now divided into two steps: (1) LeasePinger.removeClient(), which
- // just removes a reference to the Client in a LeasePinger map, and
- // (2) leasePinger.disconnectClient(), which sends a message to the server.
- // Only step (1) takes place inside the synchronization block. If it is
- // determined in step (1) that the last Client has been removed from the
- // LeasePinger, then the instance variable leasePinger is set to null.
- // Once leasePinger is set to null, the next Client that calls
- // establishLease() will have to create a new LeasePinger, which it will
- // be able to do without waiting for the completion of the network i/o
- // performed in terminateLease().
-
- LeasePinger localPinger = null;
- boolean isLastClientLease = false;
-
synchronized(clientLeaseLock)
{
- localPinger = leasePinger;
-
if(leasePinger != null)
{
- isLastClientLease = leasePinger.removeClient(sessionId);
+ leasePinger.setDisconnectTimeout(disconnectTimeout);
+ boolean isLastClientLease = leasePinger.removeClient(sessionId);
if(isLastClientLease)
{
- leasePinger = null;
- }
- }
- }
-
- if (localPinger != null)
- {
- if (isLastClientLease)
- {
- localPinger.stopPing();
- }
-
try
{
- localPinger.setDisconnectTimeout(disconnectTimeout);
- localPinger.disconnectClient(sessionId);
+ leasePinger.stopPing();
}
catch (Exception e)
{
- // The only exception thrown by LeasePinger.disconnectClient()
- // is a RuntimeException thrown by LeasePinger.disconnect().
log.error("error shutting down lease pinger");
}
+ leasePinger = null;
+ }
+ }
}
}
@@ -382,103 +349,15 @@
public void establishLease(String clientSessionID, Map configuration, long leasePeriod)
throws Throwable
{
- // The synchronization in establishLease() and terminateLease() has been
- // reorganized - see JBREM-783.
-
- // The set of org.jboss.remoting.Client's entering
- // establishLease() partitioned as follows: (1) the first Client to enter
- // the synchronization block and find leasePinger == null, and (2) all other
- // Client's. The first client is responsible for creating the LeasePinger,
- // including all necessary network i/o, and the other Client's wait until the
- // LeasePinger has been started. However, the network i/o does not take place
- // inside the synchronization block. The advantage is that other Client's
- // can call terminateLease() without being blocked.
-
- boolean pingerIsStarted = false;
- String currentSessionID = invokerSessionID;
-
synchronized (clientLeaseLock)
{
// if already have a lease pinger, then already have a client with an established
// lease and just need to update the lease pinger
if (leasePinger != null)
{
- if (leasePingerException != null)
- throw leasePingerException;
-
- if (leasePinger.isStarted())
- {
- leasePinger.addClient(clientSessionID, configuration, leasePeriod);
- pingerIsStarted = true;
- }
- else
- {
leasePinger.addClient(clientSessionID, configuration, leasePeriod);
log.debug(this + " added client with session ID " + clientSessionID + " to the lease pinger");
-
- while (true)
- {
- try
- {
- clientLeaseLock.wait();
- }
- catch (InterruptedException ignored) {}
-
- if (leasePinger == null)
return;
-
- if (leasePingerException != null)
- throw leasePingerException;
-
- break;
- }
- }
- }
- else
- {
- leasePingerException = null;
- synchronized (this)
- {
- currentSessionID += "+" + leaseCounter++;
- }
- leasePinger = new LeasePinger(this, currentSessionID);
- }
- }
-
- if (leasePinger.isStarted())
- {
- leasePinger.connectClient(leasePeriod, clientSessionID);
- return;
- }
-
- InvocationRequest ir =
- new InvocationRequest(currentSessionID, null, "$PING$", null, new HashMap(), null);
-
- int clientCount;
- int attemptCount = 0;
- Exception tempException = null;
-
- while (true)
- {
- synchronized (clientLeaseLock)
- {
- clientCount = leasePinger.getClients().size();
- if (attemptCount++ > clientCount)
- {
- if (tempException == null)
- {
- leasePingerException = new Exception("Error setting up client lease");
- }
- else
- {
- leasePingerException = tempException;
- }
-
- leasePinger.purgeClients();
- leasePinger = null;
- clientLeaseLock.notifyAll();
- throw leasePingerException;
- }
}
try
@@ -488,6 +367,9 @@
// 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);
+
Object ret = invoke(ir);
if (ret instanceof InvocationResponse)
@@ -510,43 +392,19 @@
}
}
- leasePinger.setDefaultLeasePeriod(defaultLeasePeriod);
-
- if(trace) { log.trace("server does have leasing enabled (with default lease period of " +
- defaultLeasePeriod + ") and will start a new lease pinger."); }
+ 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.addClient(clientSessionID, configuration, leasePeriod);
- leasePinger.connectClient(leasePeriod, clientSessionID);
leasePinger.startPing();
- log.debug(this + " added client with session ID " + clientSessionID + " to the lease pinger");
-
- synchronized (clientLeaseLock)
- {
- clientLeaseLock.notifyAll();
- return;
- }
- }
- else
- {
- synchronized (clientLeaseLock)
- {
- leasePinger.purgeClients();
- leasePinger = null;
- clientLeaseLock.notifyAll();
- return;
}
}
}
- else
- {
- String message = "Error setting up client lease: invalid response from server: " + ret;
- tempException = new Exception(message);
- }
- }
catch (Throwable throwable)
{
- tempException = new Exception("Error setting up client lease");
- tempException.initCause(throwable);
+ Exception e = new Exception("Error setting up client lease");
+ e.initCause(throwable);
+ throw e;
}
}
}
More information about the jboss-cvs-commits
mailing list