--- tmp/org/jacorb/orb/Delegate.java 2007-11-26 14:00:40.000000000 +0100 +++ JacORB-2.3.0.orig/src/org/jacorb/orb/Delegate.java 2007-02-15 13:56:06.000000000 +0100 @@ -49,16 +49,6 @@ import org.omg.PortableServer.Servant; import org.omg.PortableServer.ServantActivator; -import edu.emory.mathcs.backport.java.util.concurrent.Callable; -import edu.emory.mathcs.backport.java.util.concurrent.ExecutionException; -import edu.emory.mathcs.backport.java.util.concurrent.Executor; -import edu.emory.mathcs.backport.java.util.concurrent.FutureTask; -import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; -import edu.emory.mathcs.backport.java.util.concurrent.TimeoutException; -import edu.emory.mathcs.backport.java.util.concurrent.locks.Condition; -import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock; -import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock; - /** * JacORB implementation of CORBA object reference * @@ -101,8 +91,7 @@ private final Set pending_replies = new HashSet(); private final Barrier pending_replies_sync = new Barrier(); - private final Lock bind_sync = new ReentrantLock(); - private final Condition isConnected = bind_sync.newCondition(); + private final java.lang.Object bind_sync = new java.lang.Object(); private boolean locate_on_bind_performed = false; @@ -130,9 +119,7 @@ private boolean useIMR; private boolean locateOnBind; - ThreadPerTaskExecutor executor = null; - - /** + /** * 03-09-04: 1.5.2.2 * * boolean threadlocal to ensure that @@ -172,7 +159,6 @@ super(); this.orb = orb; - this.executor = new ThreadPerTaskExecutor(); } public Delegate ( org.jacorb.orb.ORB orb, ParsedIOR pior ) @@ -298,9 +284,7 @@ */ private void bind(boolean rebind) { - bind_sync.lock(); - - try + synchronized (bind_sync) { if ( bound ) { @@ -367,7 +351,6 @@ case LocateStatusType_1_2._OBJECT_HERE : { - isConnected.signalAll(); break; } @@ -420,12 +403,9 @@ } } - - } - finally - { + //wake up threads waiting for the pior - bind_sync.unlock(); + bind_sync.notifyAll(); } } @@ -445,8 +425,7 @@ public void rebind(ParsedIOR ior) { - bind_sync.lock(); - try + synchronized ( bind_sync ) { // Do the ParsedIORs currently match. final ParsedIOR originalIOR = getParsedIOR(); @@ -495,10 +474,6 @@ bind(); } - finally - { - bind_sync.unlock(); - } } public org.omg.CORBA.Request create_request( org.omg.CORBA.Object self, @@ -817,23 +792,16 @@ ClientConnection getConnection() { - bind_sync.lock(); - try + synchronized ( bind_sync ) { bind(); return connection; } - finally - { - bind_sync.unlock(); - } } public org.omg.IOP.IOR getIOR() { - bind_sync.lock(); - - try + synchronized ( bind_sync ) { if ( piorOriginal != null ) { @@ -841,52 +809,37 @@ } return getParsedIOR().getIOR(); } - finally - { - bind_sync.unlock(); - } } public byte[] getObjectId() { - bind_sync.lock(); - try + synchronized ( bind_sync ) { bind(); return POAUtil.extractOID( getParsedIOR().get_object_key() ); } - finally - { - bind_sync.unlock(); - } } public byte[] getObjectKey() { - bind_sync.lock(); - try + synchronized ( bind_sync ) { bind(); return getParsedIOR().get_object_key(); } - finally - { - bind_sync.unlock(); - } } public ParsedIOR getParsedIOR() { - bind_sync.lock(); - try + synchronized ( bind_sync ) { while ( _pior == null ) { try { - isConnected.await(); + bind_sync.wait(); } catch ( InterruptedException ie ) { @@ -896,10 +849,6 @@ return _pior; } - finally - { - bind_sync.unlock(); - } } public void resolvePOA (org.omg.CORBA.Object self) @@ -1044,6 +993,7 @@ interceptors.handle_send_request(); } + try { if ( !ros.response_expected() ) // oneway op @@ -1065,37 +1015,24 @@ pending_replies.add(receiver); } - // send the request by a background thread - // - - SendJob sendJob = new SendJob(ros, receiver); - FutureTask task = new FutureTask(sendJob); - - executor.execute(task); - - try - { - task.get(getTimeLeft(ros), TimeUnit.MILLISECONDS); - } - catch (InterruptedException e) - { - throw new TRANSIENT("interrupted while sending the request"); - } - catch (ExecutionException e) - { - if(e.getCause() instanceof SystemException) - { - throw (SystemException)e.getCause(); - } - else - { - throw new RuntimeException(e); - } - } - catch (TimeoutException e) - { - throw new TIMEOUT(e.getMessage()); - } + synchronized (bind_sync) + { + if (ros.getConnection() == connection) + { + // RequestOutputStream has been created for + // exactly this connection + connection.sendRequest(ros, receiver, ros.requestId(), true); // response + // expected + } + else + { + logger.debug("invoke: RemarshalException"); + + // RequestOutputStream has been created for + // another connection, so try again + throw new RemarshalException(); + } + } } catch ( org.omg.CORBA.SystemException cfe ) { @@ -1113,7 +1050,7 @@ } interceptors.handle_receive_exception ( cfe ); - + // The exception is a TRANSIENT, so try rebinding. if ( cfe instanceof org.omg.CORBA.TRANSIENT && try_rebind() ) { @@ -1121,8 +1058,8 @@ } throw cfe; - } - finally + } + finally { if (orb.hasRequestInterceptors()) { @@ -1144,51 +1081,6 @@ return null; } - private long getTimeLeft(RequestOutputStream ros2) - { - UtcT timo = ros2.getReplyEndTime(); - long timoMillies = java.lang.Long.MAX_VALUE; - - if(timo != null) - { - timoMillies = org.jacorb.util.Time.millisTo(timo); - } - return(timoMillies); - } - - public void doSend(RequestOutputStream ros, ReplyReceiver receiver) throws RemarshalException, InterruptedException - { - long timo = getTimeLeft(ros); - - if( bind_sync.tryLock(timo, TimeUnit.MILLISECONDS) == false) - { - throw new TIMEOUT("TIMO while doSend "); - } - - try - { - if (ros.getConnection() == connection) - { - // RequestOutputStream has been created for - // exactly this connection - connection.sendRequest(ros, receiver, ros.requestId(), true); // response - // expected - } - else - { - logger.debug("invoke: RemarshalException"); - - // RequestOutputStream has been created for - // another connection, so try again - throw new RemarshalException(); - } - } - finally - { - bind_sync.unlock(); - } - } - private void invoke_oneway (RequestOutputStream ros, ClientInterceptorHandler interceptors) throws RemarshalException, ApplicationException @@ -1240,8 +1132,7 @@ private boolean try_rebind() { - bind_sync.lock(); - try + synchronized ( bind_sync ) { if( logger.isDebugEnabled()) { @@ -1336,10 +1227,6 @@ return false; } } - finally - { - bind_sync.unlock(); - } } public void invokeInterceptors( ClientRequestInfoImpl info, short op ) @@ -1714,8 +1601,7 @@ */ public void release( org.omg.CORBA.Object self ) { - bind_sync.lock(); - try + synchronized ( bind_sync ) { if (!bound) { @@ -1739,10 +1625,6 @@ logger.debug("Delegate released!"); } } - finally - { - bind_sync.unlock(); - } } /** @@ -1770,8 +1652,7 @@ { orb.perform_work(); - bind_sync.lock(); - try + synchronized ( bind_sync ) { bind(); return new org.jacorb.orb.dii.Request( self, @@ -1780,10 +1661,6 @@ getParsedIOR().get_object_key(), operation ); } - finally - { - bind_sync.unlock(); - } } /** @@ -1817,38 +1694,19 @@ UtcT replyEndTime = getReplyEndTime(); long roundtripTimeout = getRelativeRoundtripTimeout(); - long timo = Long.MAX_VALUE; if ((roundtripTimeout != 0) || (replyEndTime != null)) { replyEndTime = Time.earliest(Time.corbaFuture (roundtripTimeout), replyEndTime); - if(replyEndTime != null) - { - timo = Time.millisTo(replyEndTime); - } - if (Time.hasPassed(replyEndTime)) { throw new TIMEOUT("Reply End Time exceeded prior to invocation", 0, CompletionStatus.COMPLETED_NO); } } - - try - { - if( bind_sync.tryLock(timo, TimeUnit.MILLISECONDS) == false) - { - throw new TIMEOUT("Reply End Time exceeded prior to invocation", - 0, CompletionStatus.COMPLETED_NO); - } - } - catch (InterruptedException e) - { - throw new TRANSIENT("interrupted while request generation"); - } - - try + + synchronized ( bind_sync ) { bind(); @@ -1886,10 +1744,6 @@ return out; } - finally - { - bind_sync.unlock(); - } } /** @@ -2089,8 +1943,7 @@ public String toString() { - bind_sync.lock(); - try + synchronized ( bind_sync ) { if ( piorOriginal != null ) { @@ -2098,10 +1951,6 @@ } return getParsedIOR().getIORString(); } - finally - { - bind_sync.unlock(); - } } public String toString( org.omg.CORBA.Object self ) @@ -2208,42 +2057,4 @@ this.notifyAll(); } } - - private class ThreadPerTaskExecutor implements Executor - { - ThreadGroup group; - - ThreadPerTaskExecutor() - { - group = new ThreadGroup("Job Runner"); - } - - public void execute(Runnable r) - { - Thread t = new Thread(group, r); - t.setDaemon(true); - t.start(); - } - } - - // a SendJob is a helper class used to send requests in background - // - private class SendJob implements Callable - { - private RequestOutputStream ros; - private ReplyReceiver receiver; - - SendJob(RequestOutputStream ros, ReplyReceiver receiver) - { - this.ros = ros; - this.receiver = receiver; - } - - public java.lang.Object call() throws Exception - { - doSend(ros, receiver); - - return(null); - } - } }