View Javadoc

1   /* This file is part of COPAL (COntext Provisioning for All).
2    *
3    * COPAL is a part of SM4All (Smart hoMes for All) project.
4    *
5    * COPAL is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * COPAL is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with COPAL. If not, see <http://www.gnu.org/licenses/>.
17   */
18  package at.ac.tuwien.infosys.sm4all.copal.api.service;
19  
20  import at.ac.tuwien.infosys.sm4all.copal.api.event.ContextEvent;
21  import at.ac.tuwien.infosys.sm4all.copal.api.event.CurrentAction;
22  import at.ac.tuwien.infosys.sm4all.copal.api.listener.ContextListener;
23  import at.ac.tuwien.infosys.sm4all.copal.api.processor.ContextProcessor;
24  import at.ac.tuwien.infosys.sm4all.copal.api.query.ContextQuery;
25  import at.ac.tuwien.infosys.sm4all.copal.api.util.Observable;
26  import at.ac.tuwien.infosys.sm4all.copal.api.util.Observer;
27  
28  /**
29   * {@link ContextListener} of {@link ContextEvent}s that were not matched by any
30   * {@link ContextQuery}.
31   * 
32   * @author sanjin
33   */
34  public interface DeadLetterChannel
35          extends
36          ContextListener,
37          Observable<DeadLetterChannel.Reason, ContextEvent, DeadLetterChannel.ChannelObserver> {
38  
39      /**
40       * Attaches specified {@link ContextListener} so it will in future receive
41       * notifications on dead {@link ContextEvent}s.
42       * 
43       * @param listener the {@link ContextListener}.
44       */
45      void attach(ContextListener listener);
46  
47      /**
48       * Detach specified {@link ContextListener} so it will not receive any
49       * future notifications on dead {@link ContextEvent}s.
50       * 
51       * @param listener the {@link ContextListener}.
52       */
53      void detach(ContextListener listener);
54  
55      /**
56       * Reason why a {@link ContextEvent} is in the {@link DeadLetterChannel}.
57       * 
58       * @author sanjin
59       */
60      public enum Reason {
61          /**
62           * A {@link ContextProcessor} for a required {@link CurrentAction} could
63           * not be found.
64           */
65          NoRequiredProcessor,
66          /**
67           * No {@link ContextQuery} is listening on this type of
68           * {@link ContextEvent}.
69           */
70          NoQueries
71      }
72  
73      /**
74       * Interface for classes that want to be used as {@link Observer}s of a
75       * {@link DeadLetterChannel}.
76       * 
77       * @author sanjin
78       */
79      interface ChannelObserver extends Observer<Reason, ContextEvent> {
80  
81          /**
82           * Called when specified {@link ContextEvent} has been delivered into a
83           * {@link DeadLetterChannel}.
84           * 
85           * @param reason the {@link Reason}.
86           * @param event the dead {@link ContextEvent}.
87           */
88          @Override
89          void update(Reason reason, ContextEvent event);
90      }
91  }