Java Code Examples for org.osgi.service.event.Event#getPropertyNames()
The following examples show how to use
org.osgi.service.event.Event#getPropertyNames() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrometheusServlet.java From karaf-decanter with Apache License 2.0 | 6 votes |
@Override public void handleEvent(Event event) { for (String property : event.getPropertyNames()) { if (event.getProperty(property) instanceof Long || event.getProperty(property) instanceof Integer) { String convertedProperty = property.replace(".", "_"); Gauge gauge = gauges.get(convertedProperty); if (gauge == null) { gauge = Gauge.build().name(convertedProperty).help(property).register(); gauges.put(convertedProperty, gauge); } if (event.getProperty(property) instanceof Long) { gauge.set((Long) event.getProperty(property)); } else if (event.getProperty(property) instanceof Integer) { gauge.set((Integer) event.getProperty(property)); } } } }
Example 2
Source File: OshiCollectorTest.java From karaf-decanter with Apache License 2.0 | 6 votes |
@Test public void test() throws Exception { DispatcherMock dispatcherMock = new DispatcherMock(); OshiCollector collector = new OshiCollector(); collector.setDispatcher(dispatcherMock); collector.activate(new Hashtable<>()); collector.run(); Assert.assertEquals(1, dispatcherMock.postedEvents.size()); Event event = dispatcherMock.postedEvents.get(0); for (String property : event.getPropertyNames()) { System.out.println(property + ":" + event.getProperty(property)); } }
Example 3
Source File: EmailFormatter.java From karaf-decanter with Apache License 2.0 | 5 votes |
private Map<String, Object> getEventAsData(Event event) { Map<String, Object> map = new HashMap<>(); for (String propertyName : event.getPropertyNames()) { map.put(propertyName, event.getProperty(propertyName)); } return map; }
Example 4
Source File: RedisAppender.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { if (EventFilter.match(event, config)) { Map<String, Object> redisMap = redissonClient.getMap(getValue(config, MAP_PROPERTY, MAP_DEFAULT)); for (String name : event.getPropertyNames()) { redisMap.put(name, event.getProperty(name)); } } }
Example 5
Source File: LogAppender.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { if (EventFilter.match(event, config)) { if (marshaller != null) { LOGGER.info(marshaller.marshal(event)); } else { StringBuilder builder = new StringBuilder(); for (String innerKey : event.getPropertyNames()) { builder.append(innerKey).append(":").append(toString(event.getProperty(innerKey))).append(" | "); } LOGGER.info(builder.toString()); } } }
Example 6
Source File: CamelAppender.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { if (EventFilter.match(event, config)) { HashMap<String, Object> data = new HashMap<>(); for (String name : event.getPropertyNames()) { data.put(name, event.getProperty(name)); } LOGGER.debug("Creating producer template"); ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); LOGGER.debug("Sending event data on {}", config.get(DESTINATION_URI_KEY)); producerTemplate.sendBody((String) config.get(DESTINATION_URI_KEY), data); } }
Example 7
Source File: EventFilter.java From karaf-decanter with Apache License 2.0 | 5 votes |
public static boolean match(Event event, Dictionary<String, Object> config) { if (config == null) { return true; } String nameExcludeRegex = (config.get(PROPERTY_NAME_EXCLUDE_CONFIG) != null) ? (String) config.get(PROPERTY_NAME_EXCLUDE_CONFIG) : null; String nameIncludeRegex = (config.get(PROPERTY_NAME_INCLUDE_CONFIG) != null) ? (String) config.get(PROPERTY_NAME_INCLUDE_CONFIG) : null; String valueExcludeRegex = (config.get(PROPERTY_VALUE_EXCLUDE_CONFIG) != null) ? (String) config.get(PROPERTY_VALUE_EXCLUDE_CONFIG) : null; String valueIncludeRegex = (config.get(PROPERTY_VALUE_INCLUDE_CONFIG) != null) ? (String) config.get(PROPERTY_VALUE_INCLUDE_CONFIG) : null; for (String name : event.getPropertyNames()) { if (nameExcludeRegex != null && name.matches(nameExcludeRegex)) { return false; } if (nameIncludeRegex != null && name.matches(nameIncludeRegex)) { return true; } if (event.getProperty(name) != null && event.getProperty(name) instanceof String) { if (valueExcludeRegex != null && ((String) event.getProperty(name)).matches(valueExcludeRegex)) { return false; } if (valueIncludeRegex != null && ((String) event.getProperty(name)).matches(valueIncludeRegex)) { return true; } } } return true; }
Example 8
Source File: InfluxDbAppender.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { if (EventFilter.match(event, config)) { String type = "decanter"; if (event.getProperty("type") != null) { type = (String) event.getProperty("type"); } Map<String, Object> eventFields = new HashMap<>(); Map<String, String> eventTags = new HashMap<>(); eventTags.putAll(globalTags); for (String propertyName : event.getPropertyNames()) { Object propertyValue = event.getProperty(propertyName); if (propertyValue != null) { if (propertyValue instanceof Number || propertyValue instanceof Boolean) { eventFields.put(propertyName, propertyValue); } else if(propertyValue instanceof String){ eventTags.put(propertyName, (String) propertyValue); } } } Point point = Point.measurement(type).fields(eventFields).tag(eventTags).build(); influxDB.write(point); } }
Example 9
Source File: DropwizardMetricsAppender.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { for (String propertyName : event.getPropertyNames()) { final Object value = event.getProperty(propertyName); if (value instanceof Number) { registry.register(propertyName, new Gauge<Number>() { @Override public Number getValue() { return (Number) value; } }); } } }
Example 10
Source File: Logger.java From karaf-decanter with Apache License 2.0 | 5 votes |
private String renderEvent(Event event) { StringBuilder builder = new StringBuilder(); builder.append("\n"); for (String property : event.getPropertyNames()) { builder.append(property).append(":").append(event.getProperty(property)).append("\n"); } return builder.toString(); }
Example 11
Source File: CamelAlerter.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { HashMap<String, Object> data = new HashMap<>(); for (String name : event.getPropertyNames()) { data.put(name, event.getProperty(name)); } ProducerTemplate producerTemplate = camelContext.createProducerTemplate(); Map<String, Object> headers = new HashMap<>(); headers.put("alertLevel", event.getProperty("alertLevel")); headers.put("alertPattern", event.getProperty("alertPattern")); headers.put("alertBackToNormal", event.getProperty("alertBackToNormal")); producerTemplate.sendBodyAndHeaders(alertDestinationUri, data, headers); }
Example 12
Source File: PassThroughProcessor.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { HashMap<String, Object> data = new HashMap<>(); data.put("processor", "passthrough"); data.put("source.topics", event.getProperty("event.topics")); for (String propertyName : event.getPropertyNames()) { data.put(propertyName, event.getProperty(propertyName)); } String[] targetTopics = targetTopic.split(","); for (String topic : targetTopics) { dispatcher.postEvent(new Event(topic, data)); } }
Example 13
Source File: AggregateProcessor.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { // merge data for (String propertyName : event.getPropertyNames()) { if (overwrite) { mergedData.put(propertyName, event.getProperty(propertyName)); } else { mergedData.put(index + "." + propertyName, event.getProperty(propertyName)); } } index++; }
Example 14
Source File: EventCollector.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void handleEvent(Event event) { String topic = event.getTopic(); Map<String, Object> data = new HashMap<>(); data.put("type", "eventadmin"); for (String property : event.getPropertyNames()) { if (property.equals("type")) { if (event.getProperty(property) != null) { data.put("eventType", (event.getProperty(property) != null) ? event.getProperty(property).toString() : null); } else { data.put("eventType", "eventadmin"); } } else if (property.equalsIgnoreCase("subject")) { if (event.getProperty(property) != null && (event.getProperty(property) instanceof Subject)) { data.put(property, convertSubject((Subject) event.getProperty(property))); } } else { data.put(property, event.getProperty(property)); } } try { PropertiesPreparator.prepare(data, properties); } catch (Exception e) { // nothing to do } Event bridge = new Event("decanter/collect/eventadmin/" + topic, data); dispatcher.sendEvent(bridge); }
Example 15
Source File: CsvMarshaller.java From karaf-decanter with Apache License 2.0 | 5 votes |
private String marshal(Event event) { StringBuilder builder = new StringBuilder(); for (String propertyName : event.getPropertyNames()) { Object propertyValue = event.getProperty(propertyName); if (propertyValue != null) { builder.append(propertyName).append("=").append(propertyValue.toString()).append(separator); } } String result = builder.toString(); result = result.substring(0, result.length() - 1); return result; }
Example 16
Source File: RawMarshaller.java From karaf-decanter with Apache License 2.0 | 5 votes |
private String marshal(Event event) { StringBuilder builder = new StringBuilder(); for (String propertyName : event.getPropertyNames()) { Object propertyValue = event.getProperty(propertyName); if (propertyName != null && propertyValue != null) { builder.append(propertyName).append("=").append(propertyValue.toString()).append("\n"); } } return builder.toString(); }
Example 17
Source File: JsonMarshaller.java From karaf-decanter with Apache License 2.0 | 5 votes |
private JsonObject marshal(Event event) { JsonObjectBuilder json = Json.createObjectBuilder(); addTimestamp(event, json); for (String key : event.getPropertyNames()) { Object value = event.getProperty(key); key = replaceDotsByUnderscores ? key.replace('.','_') : key; marshalAttribute(json, key, value); } return json.build(); }
Example 18
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static String toHTML(Event e) { StringBuffer sb = new StringBuffer(); String[] names = e.getPropertyNames(); Set<String> keys = new TreeSet<String>(); for(int i = 0; i < names.length; i++) { // if(!SKIP_KEYS.contains(names[i])) { keys.add(names[i]); } } sb.append("<html>"); sb.append("<table border=0 width=\"100%\">\n"); sb.append("<tr bgcolor=\"#eeeeee\">"); sb.append("<td valign=top align=left bgcolor=\"#eeeeee\">" + fontify(tf.format(new Date(getTime(e)))) + "</td>"); sb.append("<td valign=top align=right bgcolor=\"#eeeeee\">" + fontify(e.getTopic()) + "</td>"); sb.append("</tr>"); sb.append("<tr bgcolor=\"#eeeeee\">"); sb.append("<td valign=top colspan=2 align=left bgcolor=\"#eeeeee\">" + fontify(getMessage(e)) + "</td>"); sb.append("</tr>"); Throwable t = getException(e); if(t != null) { StringWriter w = new StringWriter(); t.printStackTrace(new PrintWriter(w)); sb.append("<td colspan=2>"); sb.append("<pre>"); sb.append(w.toString()); sb.append("</pre>"); sb.append("</td>"); } for(Iterator<String> it = keys.iterator(); it.hasNext();) { String key = it.next(); sb.append("<tr>"); sb.append("<td>"); sb.append(fontify(key)); sb.append("</td>"); sb.append("<td>"); Object val = e.getProperty(key); if(SKIP_KEYS.contains(key)) { sb.append(fontify("<i>" + val.getClass().getName() + "@" + val.hashCode() + "</i>")); } else { sb.append(objToHTML(val)); } sb.append("</td>"); sb.append("</tr>"); } sb.append("</tr>\n"); sb.append("</table>\n"); sb.append("</html>"); return sb.toString(); }
Example 19
Source File: LuceneStoreImpl.java From karaf-decanter with Apache License 2.0 | 4 votes |
@Override public String store(Event event) throws Exception { Document document = new Document(); for (String property : event.getPropertyNames()) { Object value = event.getProperty(property); if (value instanceof Long) { document.add(new LongPoint(property, ((Long) value))); document.add(new StoredField(property, ((Long) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Long.class)); } else if (value instanceof Integer) { document.add(new IntPoint(property, ((Integer) value))); document.add(new StoredField(property, ((Integer) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Integer.class)); } else if (value instanceof Float) { document.add(new FloatPoint(property, ((Float) value))); document.add(new StoredField(property, ((Integer) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Float.class)); } else if (value instanceof Double) { document.add(new DoublePoint(property, ((Double) value))); document.add(new StoredField(property, ((Double) value))); points.put(property, new PointsConfig(NumberFormat.getInstance(), Double.class)); } else { if (value != null) { String stringValue = value.toString(); if (stringValue.getBytes("UTF-8").length > 32766) { stringValue = new String(stringValue.getBytes("UTF-8"), 0, 32766, "UTF-8"); } document.add(new StringField(property, stringValue, Field.Store.YES)); } } } if (event.getProperty("alertTimestamp") == null) { long now = System.currentTimeMillis(); document.add(new LongPoint("alertTimestamp", System.currentTimeMillis())); document.add(new StoredField("alertTimestamp", now)); points.put("alertTimestamp", new PointsConfig(NumberFormat.getInstance(), Long.class)); } String uuid = UUID.randomUUID().toString(); document.add(new StringField("alertUUID", uuid, Field.Store.YES)); try { indexWriter.addDocument(document); indexWriter.commit(); } catch (Exception e) { LOGGER.warn("Can't store alert: {}", e.getMessage()); } return uuid; }