Revision: 18529
Author: oleg.kulikoff
Date: Thu May 19 19:34:03 2011
Log: Issue 2582: Endpoint activity state
http://code.google.com/p/mobicents/source/detail?r=18529
Modified:
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/CreateConnectionAction.java
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/DeleteConnectionAction.java
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/EndpointActivity.java
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/ModifyConnectionAction.java
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/NamingService.java
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/Transaction.java
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/Transactions.java
=======================================
---
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/CreateConnectionAction.java
Thu May 19 04:13:14 2011
+++
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/CreateConnectionAction.java
Thu May 19 19:34:03 2011
@@ -23,6 +23,7 @@
package org.mobicents.media.server.mgcp.controller;
import java.io.IOException;
+import org.apache.log4j.Logger;
import org.mobicents.media.server.mgcp.MgcpEvent;
import org.mobicents.media.server.mgcp.message.MgcpRequest;
import org.mobicents.media.server.mgcp.message.MgcpResponse;
@@ -83,6 +84,8 @@
private RTPJoiningTask rtpJoiningTask;
private RTPTransmissionTask rtpTransmissionTask;
+ private final static Logger logger =
Logger.getLogger(CreateConnectionAction.class);
+
protected CreateConnectionAction(Transaction tx) {
super(tx);
@@ -130,6 +133,19 @@
}
private void rollback() {
+ if (endpoints[0] != null) {
+ endpoints[0].share();
+ if (connections[0] != null) {
+ endpoints[0].deleteConnection(connections[0].id);
+ }
+ }
+
+ if (endpoints[1] != null) {
+ endpoints[1].share();
+ if (connections[1] != null) {
+ endpoints[1].deleteConnection(connections[1].id);
+ }
+ }
}
private class CheckRequestTask extends Task {
@@ -368,13 +384,20 @@
@Override
public long perform() {
try {
- lookupEndpoint(localName, 0);
+ endpoints[0] =
tx.controller.endpoints.lookup(localName.toString(), true);
+
+ if (endpoints[0].getState() ==
EndpointActivity.STATE_BUSY) {
+ logger.error("Endpoint not available");
+ rollback();
+ reject(MgcpResponseCode.ENDPOINT_NOT_AVAILABLE, new
Text("Endpoint not available"));
+ }
+
activateRTPConnectionTask.setDeadLine(getTime() +
1000000L);
submit(activateRTPConnectionTask);
} catch (Exception e) {
+ logger.error("Endpoint not available", e);
rollback();
- reject(MgcpResponseCode.ENDPOINT_NOT_AVAILABLE, new
Text(e.getMessage()));
- return 0;
+ reject(MgcpResponseCode.ENDPOINT_NOT_AVAILABLE, new
Text("Endpoint not available"));
}
return 0;
}
=======================================
---
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/DeleteConnectionAction.java
Tue May 17 06:01:04 2011
+++
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/DeleteConnectionAction.java
Thu May 19 19:34:03 2011
@@ -142,6 +142,8 @@
tx.controller.mgcpProvider.send(evt, tx.address);
} catch (IOException e) {
}
+
+ tx.end();
}
private void lookupEndpoint(Text localName) throws
ResourceUnavailableException, UnknownEndpointException {
=======================================
---
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/EndpointActivity.java
Thu May 19 04:13:14 2011
+++
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/EndpointActivity.java
Thu May 19 19:34:03 2011
@@ -41,13 +41,15 @@
private final static int N = 15;
public final static int STATE_LOCKED = 1;
- public final static int STATE_SHARED = 2;
+ public final static int STATE_FREE = 2;
+ public final static int STATE_BUSY = 3;
+
//native endpoint
private Endpoint endpoint;
private Text fullName;
//the state of this activity
- private int state = STATE_SHARED;
+ private int state = STATE_FREE;
//Request executor associated with endpoint
protected Request request;
@@ -102,32 +104,51 @@
}
/**
- * Makes this activity exclusively visible.
+ * Exclusively locks this activity.
*/
public void lock() {
this.state = STATE_LOCKED;
}
/**
- * Makes this activity fully visible.
+ * Unlocks this activity if it is not busy
*/
- public void share() {
- this.state = STATE_SHARED;
- }
+ public void share() {
+ if (this.state == STATE_LOCKED) {
+ this.state = STATE_FREE;
+ }
+ }
/**
* Creates new RTP connection.
*
+ * Creation of connection makes endpoint activity busy.
+ *
* @return connection activity.
*/
public synchronized ConnectionActivity createConnection(Call call)
throws TooManyConnectionsException, ResourceUnavailableException {
+ //create connection
Connection connection =
endpoint.createConnection(ConnectionType.RTP);
+
+ //wrap connection with relative activity
ConnectionActivity activity = connections.remove(0);
activity.wrap(call, connection);
+
+ //put connection activity into active list
activeConnections.add(activity);
+
+ //change state to BUSY what means that this connection has at least
one
+ //connection
+ this.state = STATE_BUSY;
+
return activity;
}
+ /**
+ * Deletes connection.
+ *
+ * @param id the identifier of the relative connection activity.
+ */
public synchronized void deleteConnection(Text id) {
//looking for connection with specified ID.
int index = -1;
@@ -151,6 +172,11 @@
//return object to pool
connections.add(activity);
+
+ //update state
+ if (activeConnections.isEmpty()) {
+ this.state = STATE_FREE;
+ }
}
public ConnectionActivity getConnection(Text connectionID) {
=======================================
---
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/ModifyConnectionAction.java
Tue May 17 06:01:04 2011
+++
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/ModifyConnectionAction.java
Thu May 19 19:34:03 2011
@@ -157,6 +157,8 @@
tx.controller.mgcpProvider.send(evt, tx.address);
} catch (IOException e) {
}
+
+ tx.end();
}
}
=======================================
---
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/NamingService.java
Thu May 5 06:24:33 2011
+++
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/NamingService.java
Thu May 19 19:34:03 2011
@@ -143,7 +143,7 @@
private EndpointActivity lookupAny(boolean exclusive) throws
ResourceUnavailableException {
for (int i = 0; i < queue.size(); i++) {
- if (queue.get(i).getState() == EndpointActivity.STATE_SHARED) {
+ if (queue.get(i).getState() == EndpointActivity.STATE_FREE) {
//extract object from current position
EndpointActivity endpoint = queue.remove(i);
=======================================
---
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/Transaction.java
Tue May 3 23:49:17 2011
+++
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/Transaction.java
Thu May 19 19:34:03 2011
@@ -65,14 +65,20 @@
//address
protected SocketAddress address;
+ //pool of transaction objects.
+ private Transactions transactions;
+
private final static Logger logger =
Logger.getLogger(Transaction.class);
/**
* Create new transaction executor.
*
+ * @param transactions pool of the transaction objects.
* @param Controller the controller instance.
*/
- protected Transaction(Controller controller) {
+ protected Transaction(Transactions transactions, Controller
controller) {
+ this.transactions = transactions;
this.controller = controller;
+
createConnection = new CreateConnectionAction(this);
modifyConnection = new ModifyConnectionAction(this);
deleteConnection = new DeleteConnectionAction(this);
@@ -119,8 +125,12 @@
}
+ /**
+ * Terminates this transaction.
+ */
protected synchronized void end() {
this.state = IDLE;
+ transactions.terminate(this);
}
protected void process(MgcpRequest request) {
=======================================
---
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/Transactions.java
Tue May 3 01:28:55 2011
+++
/trunk/servers/media/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/controller/Transactions.java
Thu May 19 19:34:03 2011
@@ -44,7 +44,7 @@
active = new Transaction[size];
for (int i = 0; i < pool.length; i++) {
- pool[i] = new Transaction(controller);
+ pool[i] = new Transaction(this, controller);
}
}