Skip to content

Commit

Permalink
Added Specific Session management policy for CacheBeforeConnect:
Browse files Browse the repository at this point in the history
- exporting begins at connecting, instead of at connected state. This way temporal BMRs can start collecting messages.
- exported proxies are not recycled when disconnected. They continue to gather messages until connected again.
- Imports are discarded, they will be re-requested once reconnection is completed.
  • Loading branch information
amedranogil committed Oct 10, 2017
1 parent 52497d1 commit d47a427
Showing 1 changed file with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
import org.universAAL.utilities.ioc.dependencies.impl.WaitingDependencyProxy;

/**
* Main Class for the Space Gateway. It is in charge of managing
* {@link Session Sessions}, and boot them from the configuration folder.
*
* Main Class for the Space Gateway. It is in charge of managing {@link Session
* Sessions}, and boot them from the configuration folder.
*
* @author <a href="mailto:stefano.lenzi@isti.cnr.it">Stefano "Kismet" Lenzi</a>
* @author amedrano
*
*
*/
public class Gateway implements ModuleActivator, SessionEventListener {

Expand Down Expand Up @@ -120,13 +120,15 @@ private void actualStart(final ModuleContext mc) throws Exception {
spaceManager = new PassiveDependencyProxy<SpaceManager>(context,
new Object[] { SpaceManager.class.getName() });

serializer = new PassiveDependencyProxy<MessageContentSerializer>(context,
serializer = new PassiveDependencyProxy<MessageContentSerializer>(
context,
new Object[] { MessageContentSerializer.class.getName() });

tenantManager = new PassiveDependencyProxy<TenantManager>(context,
new Object[] { TenantManager.class.getName() });

busTracker = new PassiveDependencyProxy<IBusMemberRegistry>(context, IBusMemberRegistry.busRegistryShareParams);
busTracker = new PassiveDependencyProxy<IBusMemberRegistry>(context,
IBusMemberRegistry.busRegistryShareParams);

busTracker.getObject().addListener(exporter, true);

Expand All @@ -150,7 +152,8 @@ public boolean accept(final File pathname) {
public void run() {
// create a new session for each properties file
final Configuration fc = new ConfigurationFile(p);
if (fc.getConnectionMode().equals(ConnectionMode.CLIENT)) {
if (fc.getConnectionMode().equals(
ConnectionMode.CLIENT)) {
final Session s = new Session(fc, proxypool);
s.addSessionEventListener(Gateway.getInstance());// self
newSession(p.getAbsolutePath(), s);
Expand All @@ -160,10 +163,12 @@ public void run() {
}
}
};
new Thread(task, "initialisation of " + props[i].getAbsolutePath()).start();
new Thread(task, "initialisation of "
+ props[i].getAbsolutePath()).start();
} catch (final Exception e) {
LogUtils.logError(context, getClass(), "start",
new String[] { "unable to start instance from : " + props[i].getAbsolutePath() }, e);
new String[] { "unable to start instance from : "
+ props[i].getAbsolutePath() }, e);
}
}
/*
Expand Down Expand Up @@ -245,14 +250,29 @@ public ProxyPool getPool() {

/** {@ inheritDoc} */
public void statusChange(final SessionEvent se) {
if (se.getCurrentStatus() == SessionStatus.CONNECTED) {
// session is activated, check if there is anything to export.
exporter.activatedSession(se.getSession());
} else if (se.getOldStatus() == SessionStatus.CONNECTED) {
// it has disconnected have to purge proxies without deleting the
// session
exporter.stopedSession(se.getSession());
se.getSession().removeImports();

if (!se.getSession().getCacheBeforeConnect()) {
if (se.getCurrentStatus() == SessionStatus.CONNECTED) {
// session is activated, check if there is anything to export.
exporter.activatedSession(se.getSession());
} else if (se.getOldStatus() == SessionStatus.CONNECTED) {
// disconnected, then purge proxies
// without deleting the session
exporter.stopedSession(se.getSession());
se.getSession().removeImports();
}
} else {
// For sessions with Connection cache
if (se.getOldStatus() == SessionStatus.OPENING
&& se.getCurrentStatus() == SessionStatus.CONNECTING) {
// first time connection.
exporter.activatedSession(se.getSession());
} else if (se.getOldStatus() == SessionStatus.CONNECTED) {
// disconnected, then purge Import proxies only.
// exports will continue to try to send messages and they will
// be kept until next connection.
se.getSession().removeImports();
}
}
}

Expand Down

0 comments on commit d47a427

Please sign in to comment.