本文整理汇总了Java中org.osgi.service.event.EventConstants类的典型用法代码示例。如果您正苦于以下问题:Java EventConstants类的具体用法?Java EventConstants怎么用?Java EventConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventConstants类属于org.osgi.service.event包,在下文中一共展示了EventConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activate
import org.osgi.service.event.EventConstants; //导入依赖的package包/类
@Activate
public void activate(ComponentContext context) {
Dictionary<String, Object> config = context.getProperties();
this.topic = (String)config.get("topic");
if (topic == null) {
throw new IllegalArgumentException("Config property topic must be present.");
}
String eventTopics = (String)config.get(EventConstants.EVENT_TOPIC);
Publisher<Event> fromEventAdmin = eventAdmin.from(eventTopics, Event.class);
toKafka = kafka.to(topic, ProducerRecord.class);
org.slf4j.MDC.put("inLogAppender", "true");
Flux.from(fromEventAdmin)
.doOnEach(event -> org.slf4j.MDC.put("inLogAppender", "true"))
//.log()
.map(event->toRecord(event))
.doOnError(ex -> LOGGER.error(ex.getMessage(), ex))
.subscribe(toKafka);
LOGGER.info("Kafka appender started. Listening on topic " + topic);
}
示例2: start
import org.osgi.service.event.EventConstants; //导入依赖的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);
}
示例3: onMessage
import org.osgi.service.event.EventConstants; //导入依赖的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: onMessage
import org.osgi.service.event.EventConstants; //导入依赖的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);
}
示例5: testEventTransferOnWamp
import org.osgi.service.event.EventConstants; //导入依赖的package包/类
@Test
public void testEventTransferOnWamp() {
WampController controller = createWampControllerAndConnectClient();
ArrayNode msg = json.newArray();
msg.add(MessageType.SUBSCRIBE.code());
msg.add("http://example.com/topic");
controller.onMessage(CLIENT_ID, msg);
Map<String, String> map = ImmutableMap.of("k1", "v1", "k2", "v2");
org.osgi.service.event.Event event = new org.osgi.service.event.Event("top/ic", map);
controller.handleEvent(event);
// The event should have been transferred on wamp
System.out.println(last());
assertThat(get(0).get(1).asText()).isEqualTo(TestConstants.PREFIX + "/top/ic");
assertThat(get(0).get(2).get("k1").asText()).isEqualTo("v1");
assertThat(get(0).get(2).get("k2").asText()).isEqualTo("v2");
assertThat(get(0).get(2).get(EventConstants.EVENT_TOPIC).asText()).isEqualTo("top/ic");
}
示例6: testEventTransferOnWampUsingEligible
import org.osgi.service.event.EventConstants; //导入依赖的package包/类
@Test
public void testEventTransferOnWampUsingEligible() {
WampController controller = createWampControllerAndConnectClient();
ArrayNode msg = json.newArray();
msg.add(MessageType.SUBSCRIBE.code());
msg.add("http://example.com/topic");
controller.onMessage(CLIENT_ID, msg);
clear();
Map<String, Object> map = ImmutableMap.<String, Object>of("k1", "v1", "k2", "v2",
Wamp.WAMP_ELIGIBLE_EVENT_PROPERTY, ImmutableList.of(controller.getClientById(CLIENT_ID).getValue()
.session()));
org.osgi.service.event.Event event = new org.osgi.service.event.Event("top/ic", map);
controller.handleEvent(event);
// The event should have been transferred on wamp
System.out.println(last());
assertThat(get(0).get(1).asText()).isEqualTo(TestConstants.PREFIX + "/top/ic");
assertThat(get(0).get(2).get("k1").asText()).isEqualTo("v1");
assertThat(get(0).get(2).get("k2").asText()).isEqualTo("v2");
assertThat(get(0).get(2).get(EventConstants.EVENT_TOPIC).asText()).isEqualTo("top/ic");
}
示例7: addListener
import org.osgi.service.event.EventConstants; //导入依赖的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);
}
}
}
}
}
示例8: commonSetUp
import org.osgi.service.event.EventConstants; //导入依赖的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);
}
示例9: registerEventHandler
import org.osgi.service.event.EventConstants; //导入依赖的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);
}
示例10: isServiceUpdated
import org.osgi.service.event.EventConstants; //导入依赖的package包/类
@Override
@SuppressWarnings("squid:S3923")
protected boolean isServiceUpdated(Resource config, ServiceReference reference) {
boolean updated = false;
AutomaticPackageReplicatorModel model = new AutomaticPackageReplicatorModel(config);
String triggerStr = (String) reference.getProperty(TRIGGER_KEY);
if (model.getTrigger() == TRIGGER.cron && model.getTrigger() == TRIGGER.valueOf(triggerStr) && ObjectUtils
.equals(reference.getProperty(Scheduler.PROPERTY_SCHEDULER_EXPRESSION), model.getCronTrigger())) {
updated = true;
} else if (model.getTrigger() == TRIGGER.event && model.getTrigger() == TRIGGER.valueOf(triggerStr)
&& ObjectUtils.equals(reference.getProperty(EventConstants.EVENT_TOPIC), model.getEventTopic())
&& ObjectUtils.equals(reference.getProperty(EventConstants.EVENT_FILTER), model.getEventFilter())) {
updated = true;
}
return updated;
}
示例11: registerAsEventHandler
import org.osgi.service.event.EventConstants; //导入依赖的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");
}
示例12: registerWebResourceGroupListener
import org.osgi.service.event.EventConstants; //导入依赖的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);
}
}
示例13: activate
import org.osgi.service.event.EventConstants; //导入依赖的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");
}
示例14: getHandlerServiceProperties
import org.osgi.service.event.EventConstants; //导入依赖的package包/类
/**
*
* @param topics
* Specify the topics to subscribe to - Wilcard * is applicable at the end of a String
* @param filter
* @return dictionary object that represents handler service properties.
*/
protected Dictionary<String, Object> getHandlerServiceProperties(
String[] topics, String filter) {
String[] topicsToUse = topics;
if (topicsToUse == null || topicsToUse.length == 0)
topicsToUse = new String[] { "*" };
Dictionary<String, Object> result = new Hashtable<String, Object>();
result.put(EventConstants.EVENT_TOPIC, topicsToUse);
if (filter != null && filter.length() > 0)
result.put(EventConstants.EVENT_FILTER, filter);
return result;
}
示例15: createViewer
import org.osgi.service.event.EventConstants; //导入依赖的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);
}