Revision: 16051
Author: oleg.kulikoff
Date: Sat Dec 25 07:16:26 2010
Log: Issue 1976: join/unjoin in blocking mode
http://code.google.com/p/mobicents/source/detail?r=16051
Added:
/trunk/servers/media/jsr-309/core/src/main/java/org/mobicents/javax/media/mscontrol/container/InvocationLock.java
Modified:
/trunk/servers/media/jsr-309/core/src/main/java/org/mobicents/javax/media/mscontrol/container/ContainerImpl.java
=======================================
--- /dev/null
+++
/trunk/servers/media/jsr-309/core/src/main/java/org/mobicents/javax/media/mscontrol/container/InvocationLock.java
Sat Dec 25 07:16:26 2010
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and individual contributors as
indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing
+ * of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License, v. 2.0.
+ * This program is distributed in the hope that it will be useful, but
WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License,
+ * v. 2.0 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.mobicents.javax.media.mscontrol.container;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import javax.media.mscontrol.MsControlException;
+import javax.media.mscontrol.join.JoinEvent;
+import javax.media.mscontrol.join.JoinEventListener;
+
+/**
+ * Locks method calls till join event.
+ *
+ * @author kulikov
+ */
+public class InvocationLock implements JoinEventListener {
+ private Semaphore semaphore = new Semaphore(0);
+ private JoinEvent event;
+
+ public void lock(long timeout) throws MsControlException {
+ //clean last event
+ event = null;
+
+ //try to wait
+ try {
+ semaphore.tryAcquire(timeout, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ throw new MsControlException("Interrupted");
+ }
+
+ //no new even was receive during timeout period
+ if (event == null) {
+ throw new MsControlException("No response from server during "
+ timeout + " ms");
+ }
+
+ //event received. check it.
+ if (!event.isSuccessful()) {
+ throw new MsControlException(event.getErrorText());
+ }
+
+ }
+
+ public void onEvent(JoinEvent event) {
+ this.event = event;
+ semaphore.release();
+ }
+}
=======================================
---
/trunk/servers/media/jsr-309/core/src/main/java/org/mobicents/javax/media/mscontrol/container/ContainerImpl.java
Sat Dec 25 06:54:07 2010
+++
/trunk/servers/media/jsr-309/core/src/main/java/org/mobicents/javax/media/mscontrol/container/ContainerImpl.java
Sat Dec 25 07:16:26 2010
@@ -1,7 +1,6 @@
package org.mobicents.javax.media.mscontrol.container;
import org.mobicents.javax.media.mscontrol.*;
-import jain.protocol.ip.mgcp.message.parms.ConnectionIdentifier;
import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
import java.io.Serializable;
@@ -38,9 +37,12 @@
protected EndpointIdentifier endpointName;
+ private InvocationLock invocationLock = new InvocationLock();
+
public ContainerImpl(MediaSessionImpl session, Parameters parameters) {
super(session, session.getDriver(), parameters);
this.session = session;
+ listeners.add(invocationLock);
}
public EndpointIdentifier getEndpoint() {
@@ -93,7 +95,8 @@
}
public void join(Direction direction, Joinable other) throws
MsControlException {
- System.out.println("*******************JOIN
CALLED********************");
+ joinInitiate(direction, other, null);
+ invocationLock.lock(5000);
}
@@ -118,6 +121,8 @@
}
public void unjoin(Joinable other) throws MsControlException {
+ unjoinInitiate(other, null);
+ invocationLock.lock(5000);
}
public void unjoinInitiate(Joinable other, Serializable context)
throws MsControlException {