📄 epctypefilter.java
字号:
int totalEvents = 0; if (event instanceof IdentifierEvent) { totalEvents++; Identifier identifier = ((IdentifierEvent)event).getIdentifier(); this.processOneIdentifier(identifier, this.TAG_SEEN, tagsIn); } else if (event instanceof IdentifierListEvent) { Collection identifiers = ((IdentifierListEvent)event).getTagList(); totalEvents += identifiers.size(); this.processMultipleIdentifiers(((IdentifierListEvent)event).getTagList(), this.TAG_SEEN, tagsIn); } else if (event instanceof DeltaEvent) { tagsOut = new LinkedList(); Collection identifiers = ((DeltaEvent)event).getTagsIn(); totalEvents += identifiers.size(); this.processMultipleIdentifiers(identifiers, this.TAG_IN, tagsIn); identifiers = ((DeltaEvent)event).getTagsOut(); totalEvents += identifiers.size(); this.processMultipleIdentifiers(identifiers, this.TAG_OUT, tagsOut); } else if (event instanceof MiscEvent) { processMiscEvent((MiscEvent)event); } else if (event instanceof StatusEvent) { processStatusEvent((StatusEvent)event); } else { /* * This is an unknown event. Proceed according to the property settings. */ if (this.dieOnUnknownEvent) { this.logger.log(Level.SEVERE, "Event type " + event.getClass().getName() + " not supported in EPCTypeFilter"); throw new RuntimeException("Event type " + event.getClass().getName() + " not supported in EPCTypeFilter"); } } /* * Update the counters. */ int identifierCount = tagsIn.size() + (tagsOut != null ? tagsOut.size() : 0); this.passCounter += identifierCount; this.discardCounter += (totalEvents - identifierCount); /* * Propogate the event(s) if appropriate. */ if (null != tagsOut) { /* * Send a DeltaEvent. */ DeltaEvent eventToSend = new DeltaEvent(event.getSource(), event.getTimeStamp(), event.getEventContext()); eventToSend.setTagsIn(tagsIn); eventToSend.setTagsIn(tagsOut); multicastEvent(eventToSend); } else if (identifierCount == 1) { /* * Create an IdentifierEvent and send. */ IdentifierEvent eventToSend = new IdentifierEvent((Identifier)tagsIn.get(0), event.getSource(), event.getTimeStamp(), event.getEventContext()); multicastEvent(eventToSend); } else if (identifierCount > 1) { /* * Create an IdentifierListEvent and send. */ IdentifierListEvent eventToSend = new IdentifierListEvent(event.getSource(), event.getTimeStamp(), event.getEventContext()); eventToSend.setTagList(tagsIn); multicastEvent(eventToSend); } } /** * Process a single Identifier object. This method can be used to filter out * the specified Identifier, or add properties to the specified identifier. * * When writing a filter, often this and the constructor are the only method that * will need to be modified. * * TODO: Modify this method to filter events. * * @param identifier the Identifier to examine for filtering * @param action one of TAG_SEEN, TAG_IN, TAG_OUT, specifying the tag activity * @param identifiersToSend a Collection of identifiers that will be sent */ private void processOneIdentifier(Identifier identifier, int action, Collection identifiersToSend) throws Exception { /* * To filter out this identifier, simply don't add it to the list. You can * also add properties to the identifier with code similar to: * identifier.addProperty("key", "value"); */ Class identifierClass = identifier.getClass(); Boolean interesting = (Boolean)this.epcMap.get(identifierClass); if (null != interesting && interesting.booleanValue()) { identifiersToSend.add(identifier); } } /** * Process multiple Identifier objects. By default this method calls the * processOneIdentifier method for each Identifier in the set. Generally there is * no need to modify this method when writing a filter. * * @param identifiers the Collection containing the set of Identifiers to process * @param action one of TAG_SEEN, TAG_IN, TAG_OUT, specifying the tag activity * @param identifiersToSend a Collection of identifiers that will be sent */ private void processMultipleIdentifiers(Collection identifiers, int action, Collection identifiersToSend) throws Exception { Iterator iterator = identifiers.iterator(); while (iterator.hasNext()) { Identifier identifier = (Identifier)iterator.next(); processOneIdentifier(identifier, action, identifiersToSend); } } /** * Process a MiscEvent, which can hold key/value pairs. Note that while it is possible * to put Identifier objects into a MiscEvent, the receiving filter or connector may not * be designed to fetch this information and use it. * * A better use of MiscEvent is to configure the state of downstream filters and connectors. * For example, in an asset tracking scenario in which containers of assets are being scanned * a MiscEvent could be sent to indicate that a new container is being scanned, identifying * perhaps the container name and location, and serving to reset the state of a connector that * might publish the location of all assets. * * TODO: Modify this method to filter MiscEvent objects */ private void processMiscEvent(MiscEvent event) { /* * The default behavior is to ignore the contents of the MiscEvent and send it on * to the next filter or connector. */ multicastEvent(event); } /** * Process a StatusEvent, which carries a message for downstream filters and connectors. * The StatusEvent can be used to update the user interface of an application that * is used to read tags. For example, a filter could use the StatusEvent to request the * operator to remove an item that has been in the tag detection range for too long. * * TODO: Modify this method to filter StatusEvent objects */ private void processStatusEvent(StatusEvent event) { /* * The default behavior is to ignore the message of the StatusEvent and send it on * to the next filter or connector. */ multicastEvent(event); } /** * Register this component with the specified container. * * @param container the container to register this component with */ public void register(Container container) { super.registerMBean(container.getMBeanServer()); } /** * Unregister this component from the specified container. * * @param container the container to unregister this component from */ public void unregister(Container container) { super.unregisterMBean(container.getMBeanServer()); } /** * Returns the count of the identifiers discarded by this filter. * * @return the number of discarded identifiers */ public long getDiscardedCount() { return (this.discardCounter); } /** * Returns the count of identifiers that passed through this filter. * * @return the number of processed identifiers */ public long getPassCount() { return (this.passCounter); } /** * Resets the filter counters. Both the pass counter and the discard * counter are reset as a result of calling this method. */ public void reset() { this.discardCounter = 0L; this.passCounter = 0L; } /** * Sets the log level */ public void setLogLevel(String logLevel) { Level newLevel; try { newLevel = Level.parse(logLevel); this.logger.setLevel(newLevel); /* * Log the change in log level. */ this.logger.log(Level.CONFIG, "Setting log level to {0}", newLevel); } catch (IllegalArgumentException e) { /* * This condition will occur if the logLevel string does not * identify any known level by name or number. In this case we * will simply log the discrepancy and continue. */ logger.log(Level.WARNING, "EPCTypeFilter.setLogLevel: " + "Log level " + logLevel + " not known."); } } /** * Returns the current log level. The level is retrieved from the * logger associated with this EPCTypeFilter, which has the subsystem * name "com.sun.rfid.filter". * * @return the log level in string form */ public String getLogLevel() { return (this.logger.getLevel().toString()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -