[asterisk-scf-commits] team/dlee/jrouting.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Nov 24 16:51:41 CST 2010
branch "master" has been updated
via 7be31574833728f35eb1518b62e9465e713328c3 (commit)
via bcb83bd52a5fee370590da19c1ad2e534f12b44b (commit)
from 12e75b2a09667b23e314a345c319d435d88658fa (commit)
Summary of changes:
jrouting.iml | 4 +-
jrouting.ipr | 30 ++--
.../org/asterisk/scf/jrouting/SessionRouter.java | 163 ++++++++++----------
3 files changed, 100 insertions(+), 97 deletions(-)
- Log -----------------------------------------------------------------
commit 7be31574833728f35eb1518b62e9465e713328c3
Author: David M. Lee <dlee at digium.com>
Date: Wed Nov 24 12:26:57 2010 -0600
Ported refactorings from C++.
diff --git a/src/main/java/org/asterisk/scf/jrouting/SessionRouter.java b/src/main/java/org/asterisk/scf/jrouting/SessionRouter.java
index c5b0b79..f4b3a89 100644
--- a/src/main/java/org/asterisk/scf/jrouting/SessionRouter.java
+++ b/src/main/java/org/asterisk/scf/jrouting/SessionRouter.java
@@ -58,39 +58,31 @@ public class SessionRouter extends _SessionRouterDisp {
@Override
public void routeSession(SessionPrx source, String destination, Current current) throws DestinationNotFoundException, BridgingException, EndpointUnreachableException, SessionCreationException, SourceTerminatedPreBridgingException {
- SessionListener listener = new SessionListener(adapter, source);
+ SessionListener listener = new SessionListener(source);
BaseEndpointPrx[] endpoints = lookupEndpoints(destination, current);
-
- List<SessionPrx> newSessions = new ArrayList<SessionPrx>();
- for (BaseEndpointPrx endpoint : endpoints) {
- try {
- SessionEndpointPrx sessionEndpoint = SessionEndpointPrxHelper.checkedCast(endpoint);
- if (sessionEndpoint != null) {
- SessionPrx destSession = sessionEndpoint.createSession(destination, listener.getProxy());
- listener.addSession(destSession);
- newSessions.add(destSession);
- }
- } catch (Exception e) {
- log.error("Unable to create session for " + destination, e);
- }
- }
+ List<SessionPrx> newSessions = addSessionToEndpoints(
+ endpoints, destination, listener);
if (listener.getSessions().size() < 2) {
throw new SessionCreationException(destination);
}
if (listener.isTerminated()) {
- throw new SourceTerminatedPreBridgingException(source.getEndpoint().getId());
+ throw new SourceTerminatedPreBridgingException(
+ source.getEndpoint().getId());
}
listener.unregister();
try {
- List<SessionPrx> bridgedSessions = new ArrayList<SessionPrx>();
+ List<SessionPrx> bridgedSessions =
+ new ArrayList<SessionPrx>(newSessions.size() + 1);
bridgedSessions.add(source);
bridgedSessions.addAll(newSessions);
- bridgeManagerAccessor.getBridgeManager().createBridge(bridgedSessions.toArray(new SessionPrx[bridgedSessions.size()]), null);
+ bridgeManagerAccessor.getBridgeManager().createBridge(
+ bridgedSessions.toArray(new SessionPrx[bridgedSessions.size()]),
+ null);
} catch (Exception e) {
log.debug("Exception creating the bridge", e);
throw new BridgingException(source.getEndpoint().getId(), destination);
@@ -103,34 +95,16 @@ public class SessionRouter extends _SessionRouterDisp {
@Override
public void connectBridgedSessionsWithDestination(SessionPrx sessionToReplace, String destination, Current current) throws DestinationNotFoundException, BridgingException, NotBridged, SessionCreationException, SourceTerminatedPreBridgingException {
BridgePrx bridge = sessionToReplace.getBridge();
- SessionPrx[] seq = bridge.listSessions();
- List<SessionPrx> remainingSessions = new ArrayList<SessionPrx>();
- for (SessionPrx s : seq) {
- if (!sessionToReplace.ice_getIdentity().equals(s.ice_getIdentity())) {
- remainingSessions.add(s);
- }
- }
+ List<SessionPrx> remainingSessions = getSessionsInBridge(bridge, sessionToReplace);
+ SessionListener listener = new SessionListener(remainingSessions);
- SessionListener listener = new SessionListener(adapter, remainingSessions);
-
- List<SessionPrx> newSessions = new ArrayList<SessionPrx>();
+ @SuppressWarnings({"unchecked"}) List<SessionPrx> newSessions =
+ Collections.EMPTY_LIST;
try {
BaseEndpointPrx[] endpoints = lookupEndpoints(destination, current);
-
- for (BaseEndpointPrx e : endpoints) {
- try {
- SessionEndpointPrx sessionEndpoint = SessionEndpointPrxHelper.checkedCast(e);
-
- SessionPrx destSession = sessionEndpoint.createSession(destination, listener.getProxy());
- listener.addSession(destSession);
- newSessions.add(destSession);
- } catch (Exception e1) {
- log.error("Unabled to create sessionEndpoint for " + destination, e);
- // ignore
- }
- }
+ newSessions = addSessionToEndpoints(endpoints, destination, listener);
} catch (EndpointUnreachableException e) {
- log.error("Could not read endoint", e);
+ log.error("Could not read endpoint", e);
}
if (listener.getSessions().size() < 2) {
@@ -155,36 +129,13 @@ public class SessionRouter extends _SessionRouterDisp {
@Override
public void connectBridgedSessions(SessionPrx sessionToReplace, SessionPrx bridgedSession, Current current) throws BridgingException, NotBridged, SourceTerminatedPreBridgingException {
BridgePrx mergeBridge = sessionToReplace.getBridge();
- SessionPrx[] sourceSessions = mergeBridge.listSessions();
- List<SessionPrx> preserveSessions = new ArrayList<SessionPrx>();
- for (SessionPrx s : sourceSessions) {
- if (!sessionToReplace.ice_getIdentity().equals(s.ice_getIdentity())) {
- preserveSessions.add(s);
- }
- }
+ List<SessionPrx> preserveSessions = getSessionsInBridge(mergeBridge, sessionToReplace);
- SessionListener listener = new SessionListener(adapter, preserveSessions);
+ SessionListener listener = new SessionListener(preserveSessions);
BridgePrx oldBridge = bridgedSession.getBridge();
- List<SessionPrx> migratedSessions = new ArrayList<SessionPrx>();
-
- if (oldBridge != null) {
- try {
- SessionPrx[] allSessions = oldBridge.listSessions();
-
- for (SessionPrx s : allSessions) {
- if (!s.ice_getIdentity().equals(bridgedSession.ice_getIdentity())) {
- migratedSessions.add(s);
- }
- }
-
- oldBridge.removeSessions(migratedSessions.toArray(new SessionPrx[migratedSessions.size()]));
- } catch (Exception e) {
- log.warn("Unable to remove session in", e);
- // ignore
- }
- }
+ List<SessionPrx> migratingSessions = removeSessionsFromBride(oldBridge, bridgedSession);
if (listener.isTerminated()) {
throw new SourceTerminatedPreBridgingException(preserveSessions.get(0).getEndpoint().getId());
@@ -193,12 +144,32 @@ public class SessionRouter extends _SessionRouterDisp {
listener.unregister();
try {
- mergeBridge.replaceSession(sessionToReplace, migratedSessions.toArray(new SessionPrx[migratedSessions.size()]));
+ mergeBridge.replaceSession(sessionToReplace, migratingSessions.toArray(new SessionPrx[migratingSessions.size()]));
} catch (InvalidSessions invalidSessions) {
throw new RuntimeException(invalidSessions); // todo What should we throw?
}
}
+ private List<SessionPrx> removeSessionsFromBride(BridgePrx bridge, SessionPrx except) {
+ List<SessionPrx> removedSessions = new ArrayList<SessionPrx>();
+
+ try {
+ SessionPrx[] allSessions = bridge.listSessions();
+
+ for (SessionPrx s : allSessions) {
+ if (!s.ice_getIdentity().equals(except.ice_getIdentity())) {
+ removedSessions.add(s);
+ }
+ }
+
+ bridge.removeSessions(removedSessions.toArray(new SessionPrx[removedSessions.size()]));
+ } catch (Exception e) {
+ log.warn("Unable to remove sessions", e);
+ // ignore
+ }
+ return removedSessions;
+ }
+
public void setBridgeManagerAccessor(BridgeManagerAccessor bridgeManagerAccessor) {
this.bridgeManagerAccessor = bridgeManagerAccessor;
}
@@ -223,16 +194,46 @@ public class SessionRouter extends _SessionRouterDisp {
}
}
+ private List<SessionPrx> addSessionToEndpoints(BaseEndpointPrx[] endpoints, String destination, SessionListener listener) {
+ List<SessionPrx> newSessions = new ArrayList<SessionPrx>(endpoints.length);
+ for (BaseEndpointPrx endpoint : endpoints) {
+ try {
+ SessionEndpointPrx sessionEndpoint = SessionEndpointPrxHelper.checkedCast(endpoint);
+ if (sessionEndpoint != null) {
+ SessionPrx destSession = sessionEndpoint.createSession(destination, listener.getProxy());
+ listener.addSession(destSession);
+ newSessions.add(destSession);
+ }
+ } catch (Exception e) {
+ log.error("Unable to create session for " + destination, e);
+ }
+ }
+ return newSessions;
+ }
+
+ private List<SessionPrx> getSessionsInBridge(BridgePrx bridge, SessionPrx except) {
+ List<SessionPrx> r = new ArrayList<SessionPrx>();
+ SessionPrx[] seq = bridge.listSessions();
+ for (SessionPrx s : seq) {
+ if (except == null ||
+ !except.ice_getIdentity().equals(s.ice_getIdentity())) {
+ r.add(s);
+ }
+ }
+ return r;
+ }
+
private class SessionListener extends _SessionListenerDisp {
private SessionListenerPrx proxy;
- private List<SessionPrx> sessions = new ArrayList<SessionPrx>();
+ private final List<SessionPrx> sessions = Collections.synchronizedList(
+ new ArrayList<SessionPrx>());
private boolean terminated = false;
- public SessionListener(ObjectAdapter adapter, SessionPrx source) {
- this(adapter, Arrays.asList(source));
+ public SessionListener(SessionPrx source) {
+ this(Arrays.asList(source));
}
- public SessionListener(ObjectAdapter adapter, List<SessionPrx> sessions) {
+ public SessionListener(List<SessionPrx> sessions) {
proxy = SessionListenerPrxHelper.checkedCast(adapter.addWithUUID(this));
for (SessionPrx s : sessions) {
@@ -276,14 +277,16 @@ public class SessionRouter extends _SessionRouterDisp {
@Override
public void stopped(SessionPrx session, ResponseCode responseCode, Current current) {
terminated = true;
- for (SessionPrx s : sessions) {
- try {
- if (!session.ice_getIdentity().equals(s.ice_getIdentity())) {
- s.stop(responseCode);
+ synchronized (sessions) {
+ for (SessionPrx s : sessions) {
+ try {
+ if (!session.ice_getIdentity().equals(s.ice_getIdentity())) {
+ s.stop(responseCode);
+ }
+ } catch (Exception e) {
+ log.error("Could not forward stop to " + s.toString(), e);
+ // ignore
}
- } catch (Exception e) {
- log.error("Could not forward stop", e);
- // ignore
}
}
}
commit bcb83bd52a5fee370590da19c1ad2e534f12b44b
Author: David M. Lee <dlee at digium.com>
Date: Wed Nov 24 12:26:37 2010 -0600
com.digium -> org.asterisk
diff --git a/jrouting.iml b/jrouting.iml
index 391d4ae..22a6084 100644
--- a/jrouting.iml
+++ b/jrouting.iml
@@ -10,10 +10,10 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Maven: com.digium.asteriskscf:api:0.0.1-SNAPSHOT" level="project" />
+ <orderEntry type="library" name="Maven: org.asterisk.scf:api:0.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.zeroc:ice:3.4.1-digium" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.1" level="project" />
- <orderEntry type="library" name="Maven: com.digium.asteriskscf:jlogger-1.6:0.0.1-SNAPSHOT" level="project" />
+ <orderEntry type="library" name="Maven: org.asterisk.scf:jlogger-1.6:0.0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.5" level="project" />
</component>
</module>
diff --git a/jrouting.ipr b/jrouting.ipr
index 2b095f7..dc447c3 100644
--- a/jrouting.ipr
+++ b/jrouting.ipr
@@ -253,17 +253,6 @@
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5-sources.jar!/" />
</SOURCES>
</library>
- <library name="Maven: com.digium.asteriskscf:api:0.0.1-SNAPSHOT">
- <CLASSES>
- <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT.jar!/" />
- </CLASSES>
- <JAVADOC>
- <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT-javadoc.jar!/" />
- </JAVADOC>
- <SOURCES>
- <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT-sources.jar!/" />
- </SOURCES>
- </library>
<library name="Maven: org.slf4j:slf4j-api:1.6.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar!/" />
@@ -286,15 +275,26 @@
<root url="jar://$MAVEN_REPOSITORY$/com/zeroc/ice/3.4.1-digium/ice-3.4.1-digium-sources.jar!/" />
</SOURCES>
</library>
- <library name="Maven: com.digium.asteriskscf:jlogger-1.6:0.0.1-SNAPSHOT">
+ <library name="Maven: org.asterisk.scf:api:0.0.1-SNAPSHOT">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/asterisk/scf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/asterisk/scf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/asterisk/scf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT-sources.jar!/" />
+ </SOURCES>
+ </library>
+ <library name="Maven: org.asterisk.scf:jlogger-1.6:0.0.1-SNAPSHOT">
<CLASSES>
- <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/jlogger-1.6/0.0.1-SNAPSHOT/jlogger-1.6-0.0.1-SNAPSHOT.jar!/" />
+ <root url="jar://$MAVEN_REPOSITORY$/org/asterisk/scf/jlogger-1.6/0.0.1-SNAPSHOT/jlogger-1.6-0.0.1-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC>
- <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/jlogger-1.6/0.0.1-SNAPSHOT/jlogger-1.6-0.0.1-SNAPSHOT-javadoc.jar!/" />
+ <root url="jar://$MAVEN_REPOSITORY$/org/asterisk/scf/jlogger-1.6/0.0.1-SNAPSHOT/jlogger-1.6-0.0.1-SNAPSHOT-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
- <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/jlogger-1.6/0.0.1-SNAPSHOT/jlogger-1.6-0.0.1-SNAPSHOT-sources.jar!/" />
+ <root url="jar://$MAVEN_REPOSITORY$/org/asterisk/scf/jlogger-1.6/0.0.1-SNAPSHOT/jlogger-1.6-0.0.1-SNAPSHOT-sources.jar!/" />
</SOURCES>
</library>
</component>
-----------------------------------------------------------------------
--
team/dlee/jrouting.git
More information about the asterisk-scf-commits
mailing list