View Javadoc
1   /*
2    * Created on 16-Apr-2004
3    */
4   package ca.uhn.hl7v2.protocol;
5   
6   import ca.uhn.hl7v2.HL7Exception;
7   import ca.uhn.hl7v2.model.Message;
8   import ca.uhn.hl7v2.parser.Parser;
9   
10  /**
11   * Routes messages to the appropriate application.
12   *
13   * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
14   */
15  public interface ApplicationRouter {
16      /**
17       * {@link Transportable#getMetadata() Metadata} key:
18       * Charset (MSH-18)
19       */
20      String METADATA_KEY_MESSAGE_CHARSET = "MSH-18";
21  
22      /**
23       * {@link Transportable#getMetadata() Metadata} key:
24       * Message control ID (MSH-10)
25       */
26      String METADATA_KEY_MESSAGE_CONTROL_ID = MetadataKeys.IN_MESSAGE_CONTROL_ID;
27  
28      /**
29       * {@link Transportable#getMetadata() Metadata} key:
30       * Provides the IP of the sending system for a given message
31       */
32      String METADATA_KEY_SENDING_IP = MetadataKeys.IN_SENDING_IP;
33  
34      /**
35       * {@link Transportable#getMetadata() Metadata} key:
36       * Provides the port of the sending system for a given message
37       */
38      String METADATA_KEY_SENDING_PORT = MetadataKeys.IN_SENDING_PORT;
39  
40  
41      /**
42       * Attempts to route the given message to the associated <code>Application</code>
43       * and obtain a response.
44       *
45       * @param theMessage the message to route
46       * @return the response message (this may be null, for example if the given
47       * message doesn't require an application ACK)
48       */
49      Transportableca/uhn/hl7v2/protocol/Transportable.html#Transportable">Transportable processMessage(Transportable theMessage) throws HL7Exception;
50  
51      /**
52       * @param theRoutingData message fields used in determining the appropriate destination
53       * @return true if there is a destination application for messages with the given
54       * characteristics
55       */
56      boolean hasActiveBinding(AppRoutingData theRoutingData);
57  
58      /**
59       * <p>Associates the given application with the given message parameters, so that messages
60       * with matching parameters will be sent there.  Only one application can be registered
61       * for a given set of parameters: repeated registration for a particular combination
62       * over-writes the previous one.</p>
63       * <p/>
64       * <p>Because of wildcards, there may be multiple registrations that match a given message.
65       * In this case, the first registered wins.</p>
66       *
67       * @param theRoutingData message fields used in determining the appropriate destination
68       * @param theApplication the application to which messages with these parameters should be
69       *                       sent
70       */
71      void bindApplication(AppRoutingData theRoutingData, ReceivingApplication<? extends Message> theApplication);
72  
73      /**
74       * Removes the binding for the given message parameters
75       *
76       * @param theRoutingData
77       * @return true if an application was unbound, false otherwise
78       */
79      boolean unbindApplication(AppRoutingData theRoutingData);
80  
81      /**
82       * Removes the binding for the given message parameters
83       *
84       * @param theApplication
85       * @return true if an application was unbound, false otherwise
86       */
87      boolean unbindApplication(ReceivingApplication<? extends Message> theApplication);
88  
89      /**
90       * Temporarily deactivates the binding on the given field data, if present.
91       *
92       * @param theRoutingData the fields that define a set of messages that are bound to
93       *                       some <code>Application</code>
94       */
95      void disableBinding(AppRoutingData theRoutingData);
96  
97      /**
98       * Undoes <code>disableBinding(AppRoutingData theRoutingData)</code>.
99       *
100      * @param theRoutingData the fields that define a set of messages that are bound to
101      *                       some <code>Application</code>
102      */
103     void enableBinding(AppRoutingData theRoutingData);
104 
105     /**
106      * @return the <code>Parser</code> that is used to parse inbound messages
107      * and encode outbound ones.  It may be of interest to set certain parameters
108      * of this parser.
109      */
110     Parser getParser();
111 
112     /**
113      * Sets an exception handler which will be invoked in the event of a
114      * failure during parsing, processing, or encoding of an
115      * incoming message or its response.
116      */
117     void setExceptionHandler(ReceivingApplicationExceptionHandler exceptionHandler);
118 
119     /**
120      * <p>Encapsulates the message fields used for routing of messages from the
121      * HL7 protocol to the appropriate <code>Application</code>. </p>
122      * <p/>
123      * <p>The wildcard "*" in any member indicates all values of the associated parameter.  For
124      * example the conbination "ADT", "*", "*", "*" means all ADT messages.  Each value can also
125      * be a regular expression that is matched against the corresponding field.  </p>
126      *
127      * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
128      */
129     interface AppRoutingData {
130 
131         /**
132          * @return MSH-9-1
133          */
134         String getMessageType();
135 
136         /**
137          * @return MSH-9-2
138          */
139         String getTriggerEvent();
140 
141         /**
142          * @return MSH-11-1
143          */
144         String getProcessingId();
145 
146         /**
147          * @return MSH-12
148          */
149         String getVersion();
150     }
151 
152 }