本文整理匯總了Java中org.osgi.service.event.EventAdmin.postEvent方法的典型用法代碼示例。如果您正苦於以下問題:Java EventAdmin.postEvent方法的具體用法?Java EventAdmin.postEvent怎麽用?Java EventAdmin.postEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.osgi.service.event.EventAdmin
的用法示例。
在下文中一共展示了EventAdmin.postEvent方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performAction
import org.osgi.service.event.EventAdmin; //導入方法依賴的package包/類
private void performAction(DependencyAction action, Map<MavenArtifact, ArtifactLoader> artifact2loader) throws BundleException {
LOGGER.info("Perform " + action);
EventAdmin eventAdmin = this.eventAdmin;
if (eventAdmin != null)
eventAdmin.postEvent(new DependencyActionEvent(action));
if (action instanceof InstallAction) {
performInstall(action.artifact, artifact2loader.get(action.artifact));
} else if (action instanceof UpdateAction) {
MavenArtifact target = ((UpdateAction) action).targetArtifact;
performUpdate(action.artifact, target, artifact2loader.get(target));
} else if (action instanceof UninstallAction) {
performUninstall(action.artifact);
} else {
throw new IllegalArgumentException("Unknown action: " + action);
}
}
示例2: notifyEventAdmins
import org.osgi.service.event.EventAdmin; //導入方法依賴的package包/類
@SuppressWarnings({
"rawtypes", "unchecked"
})
private void notifyEventAdmins(String topic, Event event) {
ServiceReference[] refs = null;
try {
refs = bctx.getAllServiceReferences(EventAdmin.class.getName(), null);
} catch (InvalidSyntaxException e) {
LOG.error("Failed to get EventAdmin: " + e.getMessage(), e);
}
if (refs != null) {
LOG.debug("Publishing event to {} EventAdmins; Topic:[{}]", refs.length, topic);
for (ServiceReference serviceReference : refs) {
EventAdmin eventAdmin = (EventAdmin) bctx.getService(serviceReference);
try {
eventAdmin.postEvent(event);
} finally {
if (eventAdmin != null) {
bctx.ungetService(serviceReference);
}
}
}
}
}
示例3: notify
import org.osgi.service.event.EventAdmin; //導入方法依賴的package包/類
public void notify(EventObject event) throws Exception {
EventAdmin eventAdmin = tracker.getService();
if (eventAdmin == null) {
return;
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(TYPE, getType(event));
props.put(EVENT, event);
props.put(TIMESTAMP, System.currentTimeMillis());
props.put(BUNDLE, bundleContext.getBundle());
props.put(BUNDLE_SYMBOLICNAME, bundleContext.getBundle().getSymbolicName());
props.put(BUNDLE_ID, bundleContext.getBundle().getBundleId());
props.put(BUNDLE_VERSION, getBundleVersion(bundleContext.getBundle()));
try {
props.put(CAUSE, event.getClass().getMethod("getCause").invoke(event));
} catch (Throwable t) {
// ignore
}
eventAdmin.postEvent(new Event(getTopic(event), props));
}
示例4: postEvent
import org.osgi.service.event.EventAdmin; //導入方法依賴的package包/類
public static void postEvent(String topic, Map<String, Object> data) {
BundleContext bundleContext = FrameworkUtil.getBundle(EventAdminHelper.class).getBundleContext();
if (bundleContext == null) return;
ServiceReference ref = bundleContext.getServiceReference(EventAdmin.class.getName());
if (ref != null)
{
EventAdmin eventAdmin = (EventAdmin) bundleContext.getService(ref);
HashMap<String, Object> eventData = new HashMap<>(data);
eventAdmin.postEvent(new Event(topic, eventData));
}
}
示例5: send
import org.osgi.service.event.EventAdmin; //導入方法依賴的package包/類
public void send(RemoteServiceAdminEvent rsaEvent) {
Event event = toEvent(rsaEvent);
ServiceReference<EventAdmin> sref = this.context.getServiceReference(EventAdmin.class);
if (sref != null) {
EventAdmin eventAdmin = this.context.getService(sref);
eventAdmin.postEvent(event);
this.context.ungetService(sref);
}
}
示例6: process
import org.osgi.service.event.EventAdmin; //導入方法依賴的package包/類
public void process(Exchange exchange) throws Exception {
EventAdmin admin = (EventAdmin) this.tracker.getService();
if (admin != null) {
Event event = getEvent(exchange);
if (endpoint.isSend()) {
admin.sendEvent(event);
} else {
admin.postEvent(event);
}
} else {
throw new CamelExchangeException("EventAdmin service not present", exchange);
}
}
示例7: switchyardEvent
import org.osgi.service.event.EventAdmin; //導入方法依賴的package包/類
@SuppressWarnings({"ThrowableResultOfMethodCallIgnored"})
public void switchyardEvent(SwitchYardEvent event) {
EventAdmin eventAdmin = (EventAdmin) tracker.getService();
if (eventAdmin == null) {
return;
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(EventConstants.TYPE, event.getType());
props.put(EventConstants.EVENT, event);
props.put(EventConstants.TIMESTAMP, event.getTimestamp());
props.put(EventConstants.BUNDLE, event.getBundle());
props.put(EventConstants.BUNDLE_SYMBOLICNAME, event.getBundle().getSymbolicName());
props.put(EventConstants.BUNDLE_ID, event.getBundle().getBundleId());
props.put(EventConstants.BUNDLE_VERSION, event.getBundle().getVersion());
props.put(EventConstants.EXTENDER_BUNDLE, event.getExtenderBundle());
props.put(EventConstants.EXTENDER_BUNDLE_ID, event.getExtenderBundle().getBundleId());
props.put(EventConstants.EXTENDER_BUNDLE_SYMBOLICNAME, event.getExtenderBundle().getSymbolicName());
props.put(EventConstants.EXTENDER_BUNDLE_VERSION, event.getExtenderBundle().getVersion());
if (event.getCause() != null) {
props.put(EventConstants.CAUSE, event.getCause());
}
if (event.getDependencies() != null) {
props.put(EventConstants.DEPENDENCIES, event.getDependencies());
}
String topic;
switch (event.getType()) {
case SwitchYardEvent.CREATING:
topic = EventConstants.TOPIC_CREATING;
break;
case SwitchYardEvent.CREATED:
topic = EventConstants.TOPIC_CREATED;
break;
case SwitchYardEvent.DESTROYING:
topic = EventConstants.TOPIC_DESTROYING;
break;
case SwitchYardEvent.DESTROYED:
topic = EventConstants.TOPIC_DESTROYED;
break;
case SwitchYardEvent.FAILURE:
topic = EventConstants.TOPIC_FAILURE;
break;
case SwitchYardEvent.GRACE_PERIOD:
topic = EventConstants.TOPIC_GRACE_PERIOD;
break;
default:
throw new IllegalStateException("Unknown switchyard event type: " + event.getType());
}
eventAdmin.postEvent(new Event(topic, props));
}