org.osgi.service.event.Event类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(260)

本文整理了Java中org.osgi.service.event.Event类的一些代码示例,展示了Event类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Event类的具体详情如下:
包路径:org.osgi.service.event.Event
类名称:Event

Event介绍

[英]An event. Event objects are delivered to EventHandlerservices which subscribe to the topic of the event.
[中]事件。事件对象被传递到订阅事件主题的EventHandlerservices。

代码示例

代码示例来源:origin: jersey/jersey

private void sendAdminEvent() {
  ServiceReference eaRef = bc.getServiceReference(EventAdmin.class.getName());
  if (eaRef != null) {
    EventAdmin ea = (EventAdmin) bc.getService(eaRef);
    ea.sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() {
      {
        put("context-path", "/");
      }
    }));
    bc.ungetService(eaRef);
  }
}

代码示例来源:origin: openhab/openhab1-addons

@Override
public void handleEvent(Event event) {
  String itemName = (String) event.getProperty("item");
  String topic = event.getTopic();
  String[] topicParts = topic.split(TOPIC_SEPERATOR);
  if (!(topicParts.length > 2) || !topicParts[0].equals(TOPIC_PREFIX)) {
    return; // we have received an event with an invalid topic
  }
  String operation = topicParts[1];
  if (operation.equals(EventType.UPDATE.toString())) {
    State newState = (State) event.getProperty("state");
    if (newState != null) {
      receiveUpdate(itemName, newState);
    }
  }
  if (operation.equals(EventType.COMMAND.toString())) {
    Command command = (Command) event.getProperty("command");
    if (command != null) {
      receiveCommand(itemName, command);
    }
  }
}

代码示例来源:origin: org.osgi/org.osgi.compendium

/**
 * Constructs an event.
 * 
 * @param topic The topic of the event.
 * @param properties The event's properties (may be {@code null}). A
 *        property whose key is not of type {@code String} will be ignored.
 * @throws IllegalArgumentException If topic is not a valid topic name.
 */
public Event(String topic, Dictionary<String, ?> properties) {
  validateTopicName(topic);
  this.topic = topic;
  // safely publish the event properties
  this.properties = new EventProperties(properties);
}

代码示例来源:origin: eclipse/smarthome

@Override
  public Void run() throws Exception {
    Dictionary<String, Object> properties = new Hashtable<String, Object>(3);
    properties.put("type", event.getType());
    properties.put("payload", event.getPayload());
    properties.put("topic", event.getTopic());
    if (event.getSource() != null) {
      properties.put("source", event.getSource());
    }
    eventAdmin.postEvent(new org.osgi.service.event.Event("smarthome", properties));
    return null;
  }
});

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.e4.ui.workbench

/**
 * @param event
 *            An OSGI event representing a UIEvent
 * @return true if it is a create event, false otherwise.
 */
public static boolean isCREATE(Event event) {
  return UIEvents.EventTypes.CREATE.equals(event.getProperty(UIEvents.EventTags.TYPE));
}

代码示例来源:origin: org.apache.ace/org.apache.ace.client.repository.impl

public void notifyChanged(String topic, Properties props, boolean internalOnly) {
  props = addSession(props);
  m_eventAdmin.sendEvent(new Event(m_privateTopicRoot + m_entityRoot + topic,(Dictionary) props));
  if (!internalOnly) {
    m_eventAdmin.postEvent(new Event(m_publicTopicRoot + m_entityRoot + topic, (Dictionary) props));
  }
}

代码示例来源:origin: stackoverflow.com

public class MyTestDriver {
  public static void main(String[] args) {
    Event e = new Event();
    e.setOnEventListener(new OnEventListener() {
       public void onEvent(EventObject e) {
         // do your work. 
       }
    });
    e.doEvent();
  }
}

代码示例来源:origin: org.apache.karaf.decanter.alerting/org.apache.karaf.decanter.alerting.checker

private Event populateAlertEvent(String level, Event collectEvent, String attribute, String pattern, boolean recovery) {
  Map<String, Object> data = new HashMap<>();
  data.put("alertLevel", level);
  data.put("alertAttribute", attribute);
  data.put("alertPattern", pattern);
  data.put("alertBackToNormal", recovery);
  for (String name : collectEvent.getPropertyNames()) {
    data.put(name, collectEvent.getProperty(name));
  }
  Event alertEvent = new Event("decanter/alert/" + level, data);
  return alertEvent;
}

代码示例来源:origin: apache/felix

/**
 * This method checks whether the given (i.e., calling) bundle has
 * appropriate permissions to post an event to the targeted topic. A
 * <tt>SecurityException</tt> is thrown in case it has not. Otherwise, the
 * event is posted using this decorator's service instance.
 *
 * @param event The event that should be posted
 *
 * @see org.osgi.service.event.EventAdmin#postEvent(org.osgi.service.event.Event)
 */
public void postEvent(final Event event)
{
  checkPermission(event.getTopic());
  m_admin.postEvent(event);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.distribution.core

public void handleEvent(Event event) {
    DistributionRequestType action = SlingConstants.TOPIC_RESOURCE_REMOVED.equals(event.getTopic()) ?
        DistributionRequestType.DELETE : DistributionRequestType.ADD;
    log.info("triggering distribution from event {}", event);
    for (String pn : event.getPropertyNames()) {
      log.info("property {} : {}", pn, event.getProperty(pn));
    }
    Object pathProperty = event.getProperty("path");
    if (pathProperty != null) {
      String distributingPath = String.valueOf(pathProperty);
      requestHandler.handle(null, new SimpleDistributionRequest(action, distributingPath));
    }
  }
}

代码示例来源:origin: eclipse/smarthome

public void handleEvent(org.osgi.service.event.Event osgiEvent) {
  logger.trace("Handle OSGi event (event: {})", osgiEvent);
  Object typeObj = osgiEvent.getProperty("type");
  Object payloadObj = osgiEvent.getProperty("payload");
  Object topicObj = osgiEvent.getProperty("topic");
  Object sourceObj = osgiEvent.getProperty("source");
  if (typeObj instanceof String && payloadObj instanceof String && topicObj instanceof String) {
    String typeStr = (String) typeObj;
    String payloadStr = (String) payloadObj;
    String topicStr = (String) topicObj;
    String sourceStr = (sourceObj instanceof String) ? (String) sourceObj : null;
    if (!typeStr.isEmpty() && !payloadStr.isEmpty() && !topicStr.isEmpty()) {
      handleEvent(typeStr, payloadStr, topicStr, sourceStr);
    }
  } else {
    logger.error(
        "The handled OSGi event is invalid. Expect properties as string named 'type', 'payload' and 'topic'. "
            + "Received event properties are: {}",
        Arrays.toString(osgiEvent.getPropertyNames()));
  }
}

代码示例来源:origin: osgi/osgi.enroute.examples

@Override
  public void handleEvent(Event event) {
    System.out.println("Event: " + event.getTopic());
  }
}

代码示例来源:origin: apache/felix

/**
 * This method checks whether the given (i.e., calling) bundle has
 * appropriate permissions to send an event to the targeted topic. A
 * <tt>SecurityException</tt> is thrown in case it has not. Otherwise,
 * the event is posted using this decorator's service instance.
 *
 * @param event The event that should be send
 *
 * @see org.osgi.service.event.EventAdmin#sendEvent(org.osgi.service.event.Event)
 */
public void sendEvent(final Event event)
{
  checkPermission(event.getTopic());
  m_admin.sendEvent(event);
}

代码示例来源:origin: apache/karaf

@Override
public void accept(Event event) {
  out.println(getTimeStamp(event) + " - " + event.getTopic());
  if (verbose) {
    for (String key : event.getPropertyNames()) {
      if (!key.equals("event.topics") && !key.equals("timestamp")) {
        out.println(key + ": " + getPrintValue(event, key));
      }
    }
    out.println();
    out.flush();
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.resourceresolver

/**
 * Send an OSGi event
 */
private void sendChangeEvent() {
  final EventAdmin local = this.eventAdmin;
  if (local != null) {
    final Event event = new Event(SlingConstants.TOPIC_RESOURCE_RESOLVER_MAPPING_CHANGED,
            (Dictionary<String, ?>) null);
    local.postEvent(event);
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.launchpad.test-services

public void handleEvent(Event event) {
  if (AUTH_PID.equals(event.getProperty("service.pid"))) {
    modifiedCounter++;
  }
}

代码示例来源:origin: stackoverflow.com

mybutton.setSelection(true);
mybutton.notifyListeners(SWT.Selection, new Event());

代码示例来源:origin: org.apache.felix/org.apache.felix.eventadmin

/**
 * This method checks whether the given (i.e., calling) bundle has
 * appropriate permissions to post an event to the targeted topic. A
 * <tt>SecurityException</tt> is thrown in case it has not. Otherwise, the
 * event is posted using this decorator's service instance.
 *
 * @param event The event that should be posted
 *
 * @see org.osgi.service.event.EventAdmin#postEvent(org.osgi.service.event.Event)
 */
public void postEvent(final Event event)
{
  checkPermission(event.getTopic());
  m_admin.postEvent(event);
}

代码示例来源:origin: apache/ace

private Map<String, String> getPayload(Event event) {
    Map<String, String> payload = new HashMap<>();
    for (String propertyName : event.getPropertyNames()) {
      payload.put(propertyName, event.getProperty(propertyName).toString());
    }
    return payload;
  }
}

代码示例来源:origin: apache/karaf

@Override
public boolean test(Event event) {
  return pattern.matcher(event.getTopic()).matches();
}

相关文章