本文整理匯總了Java中org.osgi.service.event.EventAdmin類的典型用法代碼示例。如果您正苦於以下問題:Java EventAdmin類的具體用法?Java EventAdmin怎麽用?Java EventAdmin使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EventAdmin類屬於org.osgi.service.event包,在下文中一共展示了EventAdmin類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: ChannelImpl
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
public ChannelImpl ( final String storageId, final EventAdmin eventAdmin, final StorageManager manager, final ChannelProviderImpl provider, final Map<MetaKey, String> configuration )
{
this.storageId = storageId;
this.manager = manager;
this.provider = provider;
this.storageKey = new MetaKey ( "channel", storageId );
String dir = configuration.get ( KEY_APM_DIR_OVERRIDE );
if ( dir == null )
{
dir = storageId;
}
this.handle = manager.registerModel ( 10_000, this.storageKey, new ChannelModelProvider ( storageId, dir ) );
}
示例5: createWampControllerAndConnectClient
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
private WampController createWampControllerAndConnectClient(Json json) {
Publisher publisher = mock(Publisher.class);
final Answer<Object> answer = new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
message.add(0, (String) invocation.getArguments()[2]);
return null;
}
};
doAnswer(answer).when(publisher).send(anyString(), anyString(), anyString());
WampController controller = new WampController(json, publisher, TestConstants.PREFIX);
controller.ea = mock(EventAdmin.class);
controller.open(CLIENT_ID);
assertThat(message).isNotNull();
return controller;
}
示例6: start
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
@Override
public void start(BundleContext context) throws Exception {
log.debug("de.iew.stagediver.fx.eventbus Bundle starting");
this.context = context;
if (this.eventBusImpl == null) {
this.eventBusImpl = new EventBusImpl();
}
if (this.eventBusServiceServiceRegistration == null) {
this.eventBusServiceServiceRegistration = context.registerService(EventBusService.class, this.eventBusImpl, null);
}
this.eventAdminServiceReference = context.getServiceReference(EventAdmin.class);
registerEventHandlerIfEventAdminIsAvailable(context);
final String filterString = String.format("(objectClass=%s)", EventAdmin.class.getName());
context.addServiceListener(this, filterString);
}
示例7: serviceChanged
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
@Override
public void serviceChanged(ServiceEvent event) {
final ServiceReference<EventAdmin> eventAdminServiceReference = (ServiceReference<EventAdmin>) event.getServiceReference();
switch (event.getType()) {
case ServiceEvent.REGISTERED:
log.debug(String.format("The service %s is registered", eventAdminServiceReference));
if (this.eventAdminServiceReference != null) {
log.warn(String.format("There is already an %s service registered. Ignoring this event.", EventAdmin.class.getName()));
} else {
this.eventAdminServiceReference = eventAdminServiceReference;
registerOSGIEventHandler(this.context);
}
break;
case ServiceEvent.UNREGISTERING:
log.debug(String.format("The service %s is unregistering", eventAdminServiceReference));
if (this.eventAdminServiceReference != null) {
unregisterOSGIEventHandler();
this.eventAdminServiceReference = null;
}
break;
}
}
示例8: sendEvent
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
private void sendEvent(Event osgiEvent) {
boolean trace = log.isTraceEnabled();
ServiceReference ref = bundleContext.getServiceReference(EVENT_ADMIN);
if (ref != null) {
EventAdmin eventAdmin = (EventAdmin) bundleContext.getService(ref);
if (eventAdmin != null) {
if (trace) {
StringBuilder sb = new StringBuilder();
String[] names = osgiEvent.getPropertyNames();
sb.append("{");
for (int i = 0; i < names.length; i++) {
String name = names[i];
sb.append(name);
sb.append("=");
Object value = osgiEvent.getProperty(name);
sb.append(ObjectUtils.getDisplayString(value));
if (i < names.length - 1)
sb.append(",");
}
sb.append("}");
log.trace("Broadcasting OSGi event " + osgiEvent + " w/ props " + sb.toString());
}
publisher.publish(eventAdmin, osgiEvent);
}
} else {
log.trace("No event admin found for broadcasting event " + osgiEvent);
}
}
示例9: Configuration
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
public Configuration(EventAdmin eventAdmin, ConfigurationAdmin cfgAdmin) {
this.eventAdmin = eventAdmin;
this.cfgAdmin = cfgAdmin;
try {
org.osgi.service.cm.Configuration cfg = this.cfgAdmin.getConfiguration("eu.hlavki.identity");
this.properties = cfg.getProperties();
} catch (IOException e) {
log.warn("Can't load configuration", e);
}
}
示例10: execute
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
EventAdmin ea = ServiceUtil.getService(EventAdmin.class);
Event stepOver = new Event(EA_TOPIC_DEBUGGING_ACTION_RESUME, Collections.emptyMap());
ea.sendEvent(stepOver);
// has to be null (see javadoc)
return null;
}
示例11: execute
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
EventAdmin ea = ServiceUtil.getService(EventAdmin.class);
Event stepOver = new Event(EA_TOPIC_DEBUGGING_ACTION_STEP_OVER, Collections.emptyMap());
ea.sendEvent(stepOver);
// has to be null (see javadoc)
return null;
}
示例12: EventAdminDestination
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
public EventAdminDestination(EventAdmin client, String topic, Class<T> type) {
this.client = client;
this.topic = topic;
if (!(type == Map.class || type==Event.class)) {
throw new IllegalArgumentException("Curently only Map<String, ?> and Event are supported");
}
this.type = type;
}
示例13: 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));
}
}
示例14: registerForEvent
import org.osgi.service.event.EventAdmin; //導入依賴的package包/類
public static void registerForEvent(EventHandler eventHandler, String... topics) {
BundleContext bundleContext = FrameworkUtil.getBundle(EventAdminHelper.class).getBundleContext();
if (bundleContext == null) return;
ServiceReference ref = bundleContext.getServiceReference(EventAdmin.class.getName());
if (ref != null)
{
Dictionary props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, topics);
bundleContext.registerService(EventHandler.class.getName(), eventHandler, props);
}
}
示例15: 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);
}
}