Commit cd6e17eb authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Added disconnect of sessions on shutdown [GATE-17], probe of sessions on...

Added disconnect of sessions on shutdown [GATE-17], probe of sessions on startup [GATE-18], switched from XXXEnabled to XXX.enabled property [GATE-21], and added various listeners.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5102 b35dd754-fafc-0310-a699-88a17e54d16e
parent 86fbcf0a
...@@ -16,11 +16,10 @@ import org.dom4j.QName; ...@@ -16,11 +16,10 @@ import org.dom4j.QName;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.container.PluginManager; import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.roster.*;
import org.jivesoftware.wildfire.roster.Roster; import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.roster.RosterEventListener;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException; import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.component.Component; import org.xmpp.component.Component;
...@@ -684,7 +683,16 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -684,7 +683,16 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Handles startup of the transport. * Handles startup of the transport.
*/ */
public void start() { public void start() {
// Do nothing. RosterEventDispatcher.addListener(this);
// Probe all registered users [if they are logged in] to auto-log them in
for (Registration registration : registrationManager.getRegistrations()) {
if (SessionManager.getInstance().getSessionCount(registration.getJID().getNode()) > 0) {
Presence p = new Presence(Presence.Type.probe);
p.setFrom(this.getJID());
p.setTo(registration.getJID());
sendPacket(p);
}
}
} }
/** /**
...@@ -693,7 +701,11 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -693,7 +701,11 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Cleans up all active sessions. * Cleans up all active sessions.
*/ */
public void shutdown() { public void shutdown() {
// TODO: actually make this function RosterEventDispatcher.removeListener(this);
// Disconnect everyone's session
for (TransportSession session : sessionManager.getSessions()) {
registrationLoggedOut(session);
}
} }
/** /**
......
...@@ -95,7 +95,7 @@ public class GatewayPlugin implements Plugin { ...@@ -95,7 +95,7 @@ public class GatewayPlugin implements Plugin {
private void maybeStartService(String serviceName) { private void maybeStartService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName); TransportInstance trInstance = transports.get(serviceName);
trInstance.startInstance(); trInstance.startInstance();
Log.debug("Starting transport service: "+serviceName); Log.info("Starting transport service: "+serviceName);
} }
/** /**
...@@ -104,7 +104,7 @@ public class GatewayPlugin implements Plugin { ...@@ -104,7 +104,7 @@ public class GatewayPlugin implements Plugin {
public void enableService(String serviceName) { public void enableService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName); TransportInstance trInstance = transports.get(serviceName);
trInstance.enable(); trInstance.enable();
Log.debug("Enabling transport service: "+serviceName); Log.info("Enabling transport service: "+serviceName);
} }
/** /**
...@@ -113,7 +113,7 @@ public class GatewayPlugin implements Plugin { ...@@ -113,7 +113,7 @@ public class GatewayPlugin implements Plugin {
public void disableService(String serviceName) { public void disableService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName); TransportInstance trInstance = transports.get(serviceName);
trInstance.disable(); trInstance.disable();
Log.debug("Disabling transport service: "+serviceName); Log.info("Disabling transport service: "+serviceName);
} }
/** /**
......
...@@ -13,6 +13,7 @@ package org.jivesoftware.wildfire.gateway; ...@@ -13,6 +13,7 @@ package org.jivesoftware.wildfire.gateway;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.PropertyEventListener; import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.PropertyEventDispatcher;
import org.xmpp.component.ComponentManager; import org.xmpp.component.ComponentManager;
import java.util.Map; import java.util.Map;
...@@ -47,7 +48,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -47,7 +48,7 @@ public class TransportInstance implements PropertyEventListener {
this.type = type; this.type = type;
this.nameOfClass = classname; this.nameOfClass = classname;
this.componentManager = componentManager; this.componentManager = componentManager;
enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+this.type.toString()+"Enabled", false); enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+this.type.toString()+".enabled", false);
} }
/** /**
...@@ -82,7 +83,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -82,7 +83,7 @@ public class TransportInstance implements PropertyEventListener {
*/ */
public void enable() { public void enable() {
enabled = true; enabled = true;
JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+"Enabled", "true"); JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+".enabled", "true");
if (!running) { if (!running) {
startInstance(); startInstance();
} }
...@@ -93,7 +94,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -93,7 +94,7 @@ public class TransportInstance implements PropertyEventListener {
*/ */
public void disable() { public void disable() {
enabled = false; enabled = false;
JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+"Enabled", "false"); JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+".enabled", "false");
if (running) { if (running) {
stopInstance(); stopInstance();
} }
...@@ -109,7 +110,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -109,7 +110,7 @@ public class TransportInstance implements PropertyEventListener {
transport = null; transport = null;
Log.debug("Loading class "+nameOfClass); //Log.debug("Loading class "+nameOfClass);
try { try {
transport = (BaseTransport)Class.forName(nameOfClass).newInstance(); transport = (BaseTransport)Class.forName(nameOfClass).newInstance();
...@@ -127,7 +128,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -127,7 +128,7 @@ public class TransportInstance implements PropertyEventListener {
try { try {
componentManager.addComponent(this.type.toString(), transport); componentManager.addComponent(this.type.toString(), transport);
//PropertyEventDispatcher.addListener(transport); PropertyEventDispatcher.addListener(this);
running = true; running = true;
} }
catch (Exception e) { catch (Exception e) {
...@@ -143,7 +144,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -143,7 +144,7 @@ public class TransportInstance implements PropertyEventListener {
return; return;
} }
//PropertyEventDispatcher.removeListener(transport); PropertyEventDispatcher.removeListener(this);
try { try {
componentManager.removeComponent(this.type.toString()); componentManager.removeComponent(this.type.toString());
} }
...@@ -162,7 +163,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -162,7 +163,7 @@ public class TransportInstance implements PropertyEventListener {
} }
public void propertySet(String property, Map params) { public void propertySet(String property, Map params) {
if (property.equals("plugin.gateway."+this.type.toString()+"Enabled")) { if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
enabled = Boolean.parseBoolean((String)params.get("value")); enabled = Boolean.parseBoolean((String)params.get("value"));
if (enabled) { if (enabled) {
if (!running) { if (!running) {
...@@ -178,7 +179,7 @@ public class TransportInstance implements PropertyEventListener { ...@@ -178,7 +179,7 @@ public class TransportInstance implements PropertyEventListener {
} }
public void propertyDeleted(String property, Map params) { public void propertyDeleted(String property, Map params) {
if (property.equals("plugin.gateway."+this.type.toString()+"Enabled")) { if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
if (running) { if (running) {
stopInstance(); stopInstance();
} }
...@@ -186,11 +187,27 @@ public class TransportInstance implements PropertyEventListener { ...@@ -186,11 +187,27 @@ public class TransportInstance implements PropertyEventListener {
} }
public void xmlPropertySet(String property, Map params) { public void xmlPropertySet(String property, Map params) {
// Ignore if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
enabled = Boolean.parseBoolean((String)params.get("value"));
if (enabled) {
if (!running) {
startInstance();
}
}
else {
if (running) {
stopInstance();
}
}
}
} }
public void xmlPropertyDeleted(String property, Map params) { public void xmlPropertyDeleted(String property, Map params) {
// Ignore if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
if (running) {
stopInstance();
}
}
} }
} }
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
package org.jivesoftware.wildfire.gateway; package org.jivesoftware.wildfire.gateway;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -72,4 +72,13 @@ public class TransportSessionManager { ...@@ -72,4 +72,13 @@ public class TransportSessionManager {
activeSessions.remove(new JID(jid.toBareJID())); activeSessions.remove(new JID(jid.toBareJID()));
} }
/**
* Retrieves a collection of all active sessions.
*
* @return List of active sessions.
*/
public Collection<TransportSession> getSessions() {
return activeSessions.values();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment