本文整理汇总了Java中org.osgi.service.event.EventHandler类的典型用法代码示例。如果您正苦于以下问题:Java EventHandler类的具体用法?Java EventHandler怎么用?Java EventHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventHandler类属于org.osgi.service.event包,在下文中一共展示了EventHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
public void start(BundleContext context) throws Exception {
System.out.println("{Core Bundle}:Running!...");
Activator.bc = context;
//ServiceReference ref = context.getServiceReference(LogConfig.class.getName());
//LogConfig conf = (LogConfig) context.getService(ref);
//conf.setFile(true);
//conf.setOut(true);
//method which starts SyMPHOnY Bundles
//startBundles(bc.getBundles());
//start miniDLNA Server on NEC
inicialization.startMiniDLNA("minidlna -f /tiny/minidlna.conf");
//set NTP pool for NTP Client on NEC
inicialization.setDate("0.openwrt.pool.ntp.org");
System.out.println("{Core Bundle}:Registering events...");
EventHandler eventHandler = new CoreEventHandler(context);
Dictionary<String, String> d = new Hashtable<String, String>();
d.put(EventConstants.EVENT_TOPIC, "symphony/event");
Activator.bc.registerService( EventHandler.class, eventHandler, d);
}
示例2: onMessage
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
public void onMessage(String message) {
// Parse the subscription request string
JsonParser parser = new JsonParser();
JsonObject object = parser.parse(message).getAsJsonObject();
String functionUID = object.get(FunctionEvent.PROPERTY_FUNCTION_UID).getAsString();
String propertyName = object.get(FunctionEvent.PROPERTY_FUNCTION_PROPERTY_NAME).getAsString();
// Prepare properties for event filter to be used with EventAdmin
Hashtable properties = new Hashtable();
properties.put(EventConstants.EVENT_TOPIC, FunctionEvent.TOPIC_PROPERTY_CHANGED);
properties.put(EventConstants.EVENT_FILTER, "(&(" + FunctionEvent.PROPERTY_FUNCTION_UID + "=" + functionUID + ")(" + FunctionEvent.PROPERTY_FUNCTION_PROPERTY_NAME + "="
+ propertyName + "))");
// unregister previous event handler
unregisterEventHandlerService();
// register event handlers
registration = this.context.getBundleContext().registerService(EventHandler.class.getName(), this, properties);
}
示例3: onMessage
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
public void onMessage(String message) {
//Parse the subscription request string
JsonParser parser=new JsonParser();
JsonObject object=parser.parse(message).getAsJsonObject();
String functionUID=object.get(FunctionEvent.PROPERTY_FUNCTION_UID).getAsString();
String propertyName=object.get(FunctionEvent.PROPERTY_FUNCTION_PROPERTY_NAME).getAsString();
//Prepare properties for event filter to be used with EventAdmin
Hashtable properties=new Hashtable();
properties.put(EventConstants.EVENT_TOPIC, FunctionEvent.TOPIC_PROPERTY_CHANGED);
properties.put(EventConstants.EVENT_FILTER, "(&("+FunctionEvent.PROPERTY_FUNCTION_UID+"="+functionUID+")("+FunctionEvent.PROPERTY_FUNCTION_PROPERTY_NAME+"="+propertyName+"))");
//unregister previous event handler
unregisterEventHandlerService();
//register event handlers
registration=this.context.getBundleContext().registerService(EventHandler.class.getName(), this, properties);
}
示例4: postContextCreate
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
@PostContextCreate
void postContextCreate(final IEventBroker eventBroker, IApplicationContext context) {
// configure log4j
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
// register for startup completed event
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() {
@Override
public void handleEvent(Event event) {
// close dynamic splash screen
Loading.close();
eventBroker.unsubscribe(this);
}
});
// close static splash screen
context.applicationRunning();
// open dynamic splash screen
Loading.open();
}
示例5: addListener
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
@Override
public void addListener(HubContext ctx, Object listener, EventCallbackInvoker invoker) {
Hashtable ht = new Hashtable();
ht.put(EventConstants.EVENT_TOPIC, EventTopics.GLOBAL);
synchronized (serviceRegMap) {
if (serviceRegMap.containsKey(listener)) {
serviceRegMap.get(listener).unregister();
}
Bundle bundle = FrameworkUtil.getBundle(getClass());
if (bundle != null) {
BundleContext context = bundle.getBundleContext();
if (context != null) {
ServiceRegistration sr = context.registerService(EventHandler.class.getName(), new EventHandlerAdapter(eventFactory, listener, invoker), ht);
if (sr != null) {
serviceRegMap.put(listener, sr);
} else {
logger.error("Received null service registration registering listener: " + listener);
}
}
}
}
}
示例6: commonSetUp
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
/**
* Common test setup.
*/
@Before
public void commonSetUp() {
super.commonSetUp();
// Get the interesting bundles
ipojoBundle = osgiHelper.getBundle(IPOJO);
testBundle = osgiHelper.getBundle(TEST_BUNDLE_SYMBOLIC_NAME);
testBundle2 = osgiHelper.getBundle(TEST_BUNDLE_2_SYMBOLIC_NAME);
// Register an EventHandler for debug
Dictionary<String, String> props = new Hashtable<String, String>();
props.put(EventConstants.EVENT_TOPIC, "everest/ipojo/*");
eventHandlerService = context.registerService(EventHandler.class, new EventHandler() {
public void handleEvent(Event event) {
System.out.println("Event " + event.getProperty("eventType") + " on path " + event.getProperty("canonicalPath"));
}
}, props);
}
示例7: registerEventHandler
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
protected void registerEventHandler() {
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put(EventConstants.EVENT_TOPIC, new String[]{"everest/osgi/*", "everest/osgi"});
osgiHelper.getContext().registerService(EventHandler.class.getName(), new EventHandler() {
public void handleEvent(Event event) {
Object eventType = event.getProperty("eventType");
//System.out.println(eventType + " " + event.getProperty("canonicalPath"));
if (ResourceEvent.CREATED.toString().equals(eventType)) {
createdEvents.add(event);
} else if (ResourceEvent.DELETED.toString().equals(eventType)) {
deletedEvents.add(event);
} else if (ResourceEvent.UPDATED.toString().equals(eventType)) {
updatedEvents.add(event);
}
}
}, props);
}
示例8: onExecute
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
@Execute
public void onExecute() {
eventBroker.subscribe(IThemeEngine.Events.THEME_CHANGED,
new EventHandler() {
public void handleEvent(Event event) {
ITheme currentTheme = (ITheme) event
.getProperty(IThemeEngine.Events.THEME);
// if (!prefDarker.getBoolean(
// THEME_DARKER_PREF_THEMEENABLED, false))
if (currentTheme.getId().equals(THEME_DARKER_ID)) {
setupPreferences();
isLastThemeDarker = true;
DarkerWeavingHook.enableWeaving();
hookDarkerCore();
} else if (isLastThemeDarker) {
DarkerWeavingHook.disableWeaving();
setToDefaultPreferences();
}
}
});
}
示例9: setup
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
@PostConstruct
public void setup(IEventBroker eventBroker){
partStack = (MPartStack)modelService.find("linguine.partstack.advanced."
+ "dataEditorPartStack", application);
eventBroker.subscribe(LinGUIneEvents.UILifeCycle.OPEN_PROJECT_DATA,
new EventHandler(){
@Override
public void handleEvent(Event event) {
if(event != null){
for(String propName: event.getPropertyNames()){
//Does nothing, but I'm afraid to get rid of it
}
}
}
});
}
示例10: registerAsEventHandler
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
@SuppressWarnings("squid:S1149")
private void registerAsEventHandler() {
final Hashtable filterProps = new Hashtable<String, String>();
// Listen on Add and Remove under /etc/acs-commons/notifications
filterProps.put(EventConstants.EVENT_TOPIC,
new String[]{
SlingConstants.TOPIC_RESOURCE_ADDED,
SlingConstants.TOPIC_RESOURCE_REMOVED });
filterProps.put(EventConstants.EVENT_FILTER, "(&"
+ "(" + SlingConstants.PROPERTY_PATH + "=" + SystemNotificationsImpl.PATH_NOTIFICATIONS + "/*)"
+ ")");
this.eventHandlerRegistration =
this.osgiComponentContext.getBundleContext().registerService(EventHandler.class.getName(), this,
filterProps);
log.debug("Registered System Notifications as Event Handler");
}
示例11: testOnAuthorEmptyNotificationsFolder
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
@Test
public void testOnAuthorEmptyNotificationsFolder() throws Exception {
setAuthorRunmode();
aemContext.build().
resource("/etc/acs-commons/notifications", JCR_PRIMARYTYPE, NT_PAGE).
resource("jcr:content", JCR_PRIMARYTYPE, NT_UNSTRUCTURED);
commit();
aemContext.registerInjectActivateService(notifications);
assertEquals(1, aemContext.getServices(EventHandler.class, null).length);
assertEquals(0, aemContext.getServices(Filter.class, null).length);
aemContext.create().resource("/etc/acs-commons/notifications/first");
commit();
sendEvent();
assertEquals(1, aemContext.getServices(Filter.class, null).length);
notifications.deactivate(aemContext.componentContext());
assertEquals(0, aemContext.getServices(Filter.class, null).length);
assertEquals(0, aemContext.getServices(EventHandler.class, null).length);
}
示例12: testOnAuthorPopulatedNotificationsFolder
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
@Test
public void testOnAuthorPopulatedNotificationsFolder() throws Exception {
setAuthorRunmode();
createEnabledNotification();
aemContext.registerInjectActivateService(notifications);
assertEquals(1, aemContext.getServices(EventHandler.class, null).length);
assertEquals(1, aemContext.getServices(Filter.class, null).length);
// then remove the resource
delete("/etc/acs-commons/notifications/enabled");
commit();
sendEvent();
assertEquals(0, aemContext.getServices(Filter.class, null).length);
notifications.deactivate(aemContext.componentContext());
assertEquals(0, aemContext.getServices(Filter.class, null).length);
assertEquals(0, aemContext.getServices(EventHandler.class, null).length);
}
示例13: registerWebResourceGroupListener
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
private void registerWebResourceGroupListener(final String webResourceName,
final String webResourcePath) throws RepositoryException {
if (!webResourceServiceRegistration.containsKey(webResourceName)) {
String[] topics = new String[] {
SlingConstants.TOPIC_RESOURCE_ADDED,
SlingConstants.TOPIC_RESOURCE_CHANGED,
SlingConstants.TOPIC_RESOURCE_REMOVED };
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(EventConstants.EVENT_TOPIC, topics);
props.put(EventConstants.EVENT_FILTER, "(path=" + webResourcePath
+ "/*)");
this.webResourceServiceRegistration.put(webResourceName,
bundleContext.registerService(EventHandler.class.getName(),
new InventoryEventHandler(), props));
log.info("Registered Inventory Event Handler for "
+ webResourceName);
}
}
示例14: activate
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
protected void activate(ComponentContext context) {
bundleContext = context.getBundleContext();
this.executorService = Executors.newFixedThreadPool(4);
compilePaths(new ArrayList<String>(
this.webResourceInventoryManager.getAllWebResourcePaths()));
String[] compileTopics = new String[] {
WebResourceInventoryManager.COMPILE_EVENT,
WebResourceInventoryManager.COMPILE_ALL_EVENT };
Dictionary<String, Object> backgroundCompilerProps = new Hashtable<String, Object>();
backgroundCompilerProps.put(EventConstants.EVENT_TOPIC, compileTopics);
bundleContext.registerService(EventHandler.class.getName(), this,
backgroundCompilerProps);
log.debug("Background Compiler Activated");
}
示例15: createViewer
import org.osgi.service.event.EventHandler; //导入依赖的package包/类
private void createViewer(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK | SWT.READ_ONLY | SWT.PUSH);
createColumns(parent, viewer);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.getTable().addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(org.eclipse.swt.widgets.Event event) {
if (highlightNodes.getSelection())
highlightNodesOnGraph(highlightNodes.getSelection());
}
});
viewer.setContentProvider(new ArrayContentProvider());
viewer.setInput(this.units);
getSite().setSelectionProvider(viewer);
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
Hashtable<String, Object> properties = new Hashtable<>();
String[] topics = new String[] { DataModel.EA_TOPIC_DATA_SELECTION, DataModel.EA_TOPIC_DATA_UNIT_CHANGED, DataModel.EA_TOPIC_DATA_VIEW_REFRESH };
properties.put(EventConstants.EVENT_TOPIC, topics);
ServiceUtil.registerService(EventHandler.class, this, properties);
}