Skip to content

Commit

Permalink
Core: rename some events (#261).
Browse files Browse the repository at this point in the history
3 core events are renamed:
    SERVICE_ARRIVED   -> PLUGIN_SERVICE_ARRIVED
    SERVICE_GONE      -> PLUGIN_SERVICE_GONE
    ALL_PLUGINS_READY -> ALL_PLUGINS_ACTIVE
The listener interfaces and and handler methods are renamed accordingly.

1 internal OSGi event is renamed:
    PLUGIN_READY      -> PLUGIN_ACTIVATED

See ticket 261.
  • Loading branch information
jri committed Jul 3, 2012
1 parent 2ddc28b commit d5b2784
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import de.deepamehta.core.service.listener.PreSendTopicListener;
import de.deepamehta.core.service.listener.PreSendTopicTypeListener;
import de.deepamehta.core.service.listener.PostInstallPluginListener;
import de.deepamehta.core.service.listener.ServiceArrivedListener;
import de.deepamehta.core.service.listener.ServiceGoneListener;
import de.deepamehta.core.service.listener.PluginServiceArrivedListener;
import de.deepamehta.core.service.listener.PluginServiceGoneListener;
import de.deepamehta.core.util.JavaUtils;

import javax.ws.rs.DefaultValue;
Expand Down Expand Up @@ -60,8 +60,8 @@ public class AccessControlPlugin extends Plugin implements AccessControlService,
PreSendTopicTypeListener,
PostInstallPluginListener,
IntroduceTopicTypeListener,
ServiceArrivedListener,
ServiceGoneListener {
PluginServiceArrivedListener,
PluginServiceGoneListener {

private static final String DEFAULT_USERNAME = "admin";
private static final String DEFAULT_PASSWORD = "";
Expand Down Expand Up @@ -259,7 +259,7 @@ public void postInstallPlugin() {
}

@Override
public void serviceArrived(PluginService service) {
public void pluginServiceArrived(PluginService service) {
logger.info("########## Service arrived: " + service);
if (service instanceof FacetsService) {
facetsService = (FacetsService) service;
Expand All @@ -269,7 +269,7 @@ public void serviceArrived(PluginService service) {
}

@Override
public void serviceGone(PluginService service) {
public void pluginServiceGone(PluginService service) {
logger.info("########## Service gone: " + service);
if (service == facetsService) {
facetsService = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,23 +589,23 @@ public ObjectFactory getObjectFactory() {


@Override
public void checkAllPluginsReady() {
public void checkAllPluginsActive() {
Bundle[] bundles = bundleContext.getBundles();
int plugins = 0;
int ready = 0;
int active = 0;
for (Bundle bundle : bundles) {
if (isDeepaMehtaPlugin(bundle)) {
plugins++;
if (isPluginRegistered(bundle.getSymbolicName())) {
ready++;
active++;
}
}
}
logger.info("### Bundles total: " + bundles.length +
", DeepaMehta plugins: " + plugins + ", Ready: " + ready);
if (plugins == ready) {
logger.info("########## All plugins ready ##########");
fireEvent(CoreEvent.ALL_PLUGINS_READY);
", DeepaMehta plugins: " + plugins + ", Active: " + active);
if (plugins == active) {
logger.info("########## All Plugins Active ##########");
fireEvent(CoreEvent.ALL_PLUGINS_ACTIVE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* - internal plugin events: are fired by a plugin and then delivered only to itself. There are 4 internal events:
* - POST_INSTALL_PLUGIN
* - INTRODUCE_TOPIC_TYPE (has a double nature)
* - SERVICE_ARRIVED
* - SERVICE_GONE
* - PLUGIN_SERVICE_ARRIVED
* - PLUGIN_SERVICE_GONE
*
* @see de.deepamehta.core.service.listener
*/
Expand Down Expand Up @@ -54,19 +54,19 @@ public enum CoreEvent {
"postInstallPlugin"),
// Note: this is an internal plugin event (see {@link Plugin#installPluginInDB}).

ALL_PLUGINS_READY(AllPluginsReadyListener.class,
"allPluginsReady"),
ALL_PLUGINS_ACTIVE(AllPluginsActiveListener.class,
"allPluginsActive"),

INTRODUCE_TOPIC_TYPE(IntroduceTopicTypeListener.class,
"introduceTopicType", TopicType.class, ClientState.class),
// Note: besides regular firing (see {@link EmbeddedService#createTopicType})
// this is an internal plugin event (see {@link Plugin#introduceTypesToPlugin}).

SERVICE_ARRIVED(ServiceArrivedListener.class,
"serviceArrived", PluginService.class),
PLUGIN_SERVICE_ARRIVED(PluginServiceArrivedListener.class,
"pluginServiceArrived", PluginService.class),
// Note: this is an internal plugin event (see {@link Plugin#createServiceTracker}).
SERVICE_GONE(ServiceGoneListener.class,
"serviceGone", PluginService.class)
PLUGIN_SERVICE_GONE(PluginServiceGoneListener.class,
"pluginServiceGone", PluginService.class)
// Note: this is an internal plugin event (see {@link Plugin#createServiceTracker}).
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ Association getAssociation(String assocTypeUri, long topic1Id, long topic2Id,

/**
* Checks if all DeepaMehta plugin bundles are registered at core.
* Fires the {@link CoreEvent.ALL_PLUGINS_READY} event if so.
* Fires the {@link CoreEvent.ALL_PLUGINS_ACTIVE} event if so.
* <p>
* Called from the Plugin class.
* Not meant to be called by a plugin developer.
*/
void checkAllPluginsReady();
void checkAllPluginsActive();

/**
* Setups the database to be compatible with this core service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Plugin implements BundleActivator, EventHandler {
// ------------------------------------------------------------------------------------------------------- Constants

private static final String PLUGIN_CONFIG_FILE = "/plugin.properties";
private static final String PLUGIN_READY = "de/deepamehta/core/plugin_ready"; // topic of the OSGi event
private static final String PLUGIN_ACTIVATED = "de/deepamehta/core/plugin_activated"; // topic of the OSGi event

// ---------------------------------------------------------------------------------------------- Instance Variables

Expand All @@ -66,7 +66,7 @@ public class Plugin implements BundleActivator, EventHandler {
// Consumed services
protected DeepaMehtaService dms;
private WebPublishingService webPublishingService;
private EventAdmin eventService; // needed to post the PLUGIN_READY OSGi event
private EventAdmin eventService; // needed to post the PLUGIN_ACTIVATED OSGi event

// Provided OSGi service
private ServiceRegistration registration;
Expand Down Expand Up @@ -226,7 +226,7 @@ public void stop(BundleContext context) {
public void handleEvent(Event event) {
String pluginUri = null;
try {
if (!event.getTopic().equals(PLUGIN_READY)) {
if (!event.getTopic().equals(PLUGIN_ACTIVATED)) {
throw new RuntimeException("Unexpected event: " + event);
}
//
Expand All @@ -235,10 +235,10 @@ public void handleEvent(Event event) {
return;
}
//
logger.info("Handling PLUGIN_READY event from \"" + pluginUri + "\" for " + this);
logger.info("Handling PLUGIN_ACTIVATED event from \"" + pluginUri + "\" for " + this);
checkServiceAvailability();
} catch (Exception e) {
logger.severe("Handling PLUGIN_READY event from \"" + pluginUri + "\" for " + this + " failed:");
logger.severe("Handling PLUGIN_ACTIVATED event from \"" + pluginUri + "\" for " + this + " failed:");
e.printStackTrace();
// Note: we don't throw through the OSGi container here. It would not print out the stacktrace.
}
Expand Down Expand Up @@ -361,10 +361,13 @@ private void openServiceTrackers(List<ServiceTracker> serviceTrackers) {

private void closeServiceTrackers(List<ServiceTracker> serviceTrackers) {
// Note: we close the service trackers in reverse creation order. Consider this case: when a consumed plugin
// service goes away the core service is still needed to deliver the SERVICE_GONE event. ### STILL TRUE?
ListIterator<ServiceTracker> i = serviceTrackers.listIterator(serviceTrackers.size());
// service goes away the core service is still needed to deliver the PLUGIN_SERVICE_GONE event. ### STILL TRUE?
/* ListIterator<ServiceTracker> i = serviceTrackers.listIterator(serviceTrackers.size());
while (i.hasPrevious()) {
i.previous().close();
} */
for (ServiceTracker serviceTracker : serviceTrackers) {
serviceTracker.close();
}
}

Expand All @@ -389,14 +392,14 @@ private void addService(Object service, String serviceInterface) {
checkServiceAvailability();
} else if (service instanceof PluginService) {
logger.info("Adding \"" + serviceInterface + "\" to " + this);
deliverEvent(CoreEvent.SERVICE_ARRIVED, (PluginService) service);
deliverEvent(CoreEvent.PLUGIN_SERVICE_ARRIVED, (PluginService) service);
}
}

private void removeService(Object service, String serviceInterface) {
if (service == dms) {
logger.info("Removing DeepaMehta 4 core service from " + this);
closePluginServiceTrackers(); // core service is needed to deliver the SERVICE_GONE event
closePluginServiceTrackers(); // core service is needed to deliver the PLUGIN_SERVICE_GONE events
unregisterListeners();
unregisterPlugin();
dms = null;
Expand All @@ -410,7 +413,7 @@ private void removeService(Object service, String serviceInterface) {
eventService = null;
} else if (service instanceof PluginService) {
logger.info("Removing plugin service \"" + serviceInterface + "\" from " + this);
deliverEvent(CoreEvent.SERVICE_GONE, (PluginService) service);
deliverEvent(CoreEvent.PLUGIN_SERVICE_GONE, (PluginService) service);
}
}

Expand All @@ -421,22 +424,22 @@ private void removeService(Object service, String serviceInterface) {
*
* The requirements:
* - the 3 core services are available (DeepaMehtaService, WebPublishingService, EventAdmin).
* - the plugins this plugin depends on (according to this plugin's "importModels" property) are active.
* - the plugin dependencies (according to this plugin's "importModels" property) are active.
*
* After activation:
* - posts the PLUGIN_READY OSGi event.
* - checks if all plugins are active, and if so, fires the {@link CoreEvent.ALL_PLUGINS_READY} event.
* - posts the PLUGIN_ACTIVATED OSGi event.
* - checks if all plugins are active, and if so, fires the {@link CoreEvent.ALL_PLUGINS_ACTIVE} event.
*/
private void checkServiceAvailability() {
// Note: The Web Publishing service is not strictly required for activation, but we must ensure
// ALL_PLUGINS_READY is not fired before the Web Publishing service becomes available.
// ALL_PLUGINS_ACTIVE is not fired before the Web Publishing service becomes available.
if (dms == null || webPublishingService == null || eventService == null || !dependenciesAvailable()) {
return;
}
//
if (activate()) {
postPluginReadyEvent();
dms.checkAllPluginsReady();
postPluginActivatedEvent();
dms.checkAllPluginsActive();
}
}

Expand Down Expand Up @@ -644,8 +647,8 @@ private List<CoreEvent> getEvents() {
* There are 4 internal events:
* - POST_INSTALL_PLUGIN
* - INTRODUCE_TOPIC_TYPE
* - SERVICE_ARRIVED
* - SERVICE_GONE
* - PLUGIN_SERVICE_ARRIVED
* - PLUGIN_SERVICE_GONE
*/
private Object deliverEvent(CoreEvent event, Object... params) {
if (!isListener(event)) {
Expand Down Expand Up @@ -831,15 +834,15 @@ private boolean dependenciesAvailable() {
}

private void registerEventListener() {
String[] topics = new String[] {PLUGIN_READY};
String[] topics = new String[] {PLUGIN_ACTIVATED};
Hashtable properties = new Hashtable();
properties.put(EventConstants.EVENT_TOPIC, topics);
context.registerService(EventHandler.class.getName(), this, properties);
}

private void postPluginReadyEvent() {
private void postPluginActivatedEvent() {
Properties properties = new Properties();
properties.put(EventConstants.BUNDLE_SYMBOLICNAME, pluginUri);
eventService.postEvent(new Event(PLUGIN_READY, properties));
eventService.postEvent(new Event(PLUGIN_ACTIVATED, properties));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@



public interface AllPluginsReadyListener extends Listener {
public interface AllPluginsActiveListener extends Listener {

void allPluginsReady();
void allPluginsActive();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



public interface ServiceGoneListener extends Listener {
public interface PluginServiceArrivedListener extends Listener {

void serviceGone(PluginService service);
void pluginServiceArrived(PluginService service);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



public interface ServiceArrivedListener extends Listener {
public interface PluginServiceGoneListener extends Listener {

void serviceArrived(PluginService service);
void pluginServiceGone(PluginService service);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import de.deepamehta.core.model.TopicRoleModel;
import de.deepamehta.core.service.Plugin;
import de.deepamehta.core.service.PluginService;
import de.deepamehta.core.service.listener.ServiceArrivedListener;
import de.deepamehta.core.service.listener.ServiceGoneListener;
import de.deepamehta.core.service.listener.PluginServiceArrivedListener;
import de.deepamehta.core.service.listener.PluginServiceGoneListener;
import de.deepamehta.core.util.JavaUtils;

import javax.ws.rs.GET;
Expand All @@ -30,8 +30,8 @@

@Path("/files")
@Produces("application/json")
public class FilesPlugin extends Plugin implements FilesService, ServiceArrivedListener,
ServiceGoneListener {
public class FilesPlugin extends Plugin implements FilesService, PluginServiceArrivedListener,
PluginServiceGoneListener {

// ---------------------------------------------------------------------------------------------- Instance Variables

Expand Down Expand Up @@ -162,15 +162,15 @@ public void openFile(@PathParam("id") long fileTopicId) {


@Override
public void serviceArrived(PluginService service) {
public void pluginServiceArrived(PluginService service) {
logger.info("########## Service arrived: " + service);
if (service instanceof ProxyService) {
proxyService = (ProxyService) service;
}
}

@Override
public void serviceGone(PluginService service) {
public void pluginServiceGone(PluginService service) {
logger.info("########## Service gone: " + service);
if (service == proxyService) {
proxyService = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import de.deepamehta.core.service.Directive;
import de.deepamehta.core.service.Directives;
import de.deepamehta.core.service.Plugin;
import de.deepamehta.core.service.listener.AllPluginsReadyListener;
import de.deepamehta.core.service.listener.AllPluginsActiveListener;
import de.deepamehta.core.service.listener.PreUpdateTopicListener;
import de.deepamehta.core.service.listener.PostUpdateTopicListener;
import de.deepamehta.core.util.JSONHelper;
Expand Down Expand Up @@ -45,7 +45,7 @@
@Produces("application/json")
public class WebclientPlugin extends Plugin implements PreUpdateTopicListener,
PostUpdateTopicListener,
AllPluginsReadyListener {
AllPluginsActiveListener {

// ---------------------------------------------------------------------------------------------- Instance Variables

Expand Down Expand Up @@ -135,7 +135,7 @@ public Topic getTopics(@PathParam("type_uri") String typeUri,


@Override
public void allPluginsReady() {
public void allPluginsActive() {
String webclientUrl = getWebclientUrl();
//
if (hasWebclientLaunched == true) {
Expand Down

0 comments on commit d5b2784

Please sign in to comment.