KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > router > AbstractRouterKeyBasedImpl


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact : dream@objectweb.org
20  *
21  * Initial developer(s): Vivien Quema
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.router;
26
27 import java.util.Hashtable JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.objectweb.dream.Push;
31 import org.objectweb.dream.PushException;
32 import org.objectweb.dream.message.Message;
33
34 /**
35  * Abstract implementation of a key-based Push/Push router. A key-based
36  * Push/Push router associates each of its outputs (except the default one) to a
37  * key. These mappings (key,outputs) are stored in the
38  * <code>outPushRouteTable</code> Map. The key corresponding to an incoming
39  * message is retrieved using the abstract
40  * {@link AbstractRouterKeyBasedImpl#getOutputKey(Message)}method. <br>
41  * The <code>outPushRouteTable</code> Map is intended to be built by the
42  * {@link AbstractRouterKeyBasedImpl#initRouteTable() }method. To avoid
43  * unnecessary building of the <code>outPushRouteTable</code> Map, the
44  * {@link AbstractRouterKeyBasedImpl#initRouteTable() }should test the
45  * <code>initialized</code> boolean which is set to <code>false</code> each
46  * time the router is bound to a new output.
47  */

48 public abstract class AbstractRouterKeyBasedImpl extends AbstractRouterImpl
49 {
50
51   /**
52    * Route table that associates keys with <code>Push</code> output
53    * interfaces.
54    */

55   protected Map JavaDoc outPushRouteTable;
56
57   /**
58    * Constructor.
59    */

60   public AbstractRouterKeyBasedImpl()
61   {
62     super();
63     outPushRouteTable = new Hashtable JavaDoc();
64   }
65
66   /**
67    * @see org.objectweb.dream.router.AbstractRouterImpl#getOutput(org.objectweb.dream.message.Message,
68    * java.util.Map)
69    */

70   protected Push getOutput(Message message, Map JavaDoc context) throws PushException
71   {
72     initRouteTable();
73     Object JavaDoc key = getOutputKey(message);
74     if (key == null)
75     {
76       return null;
77     }
78     return (Push) outPushRouteTable.get(key);
79   }
80
81   /**
82    * Returns the key associated with the output on which the specified message
83    * must be routed.
84    *
85    * @param message the message that must be routed.
86    * @return the key associated with the output on which the specified message
87    * must be routed.
88    */

89   protected abstract Object JavaDoc getOutputKey(Message message);
90
91   /**
92    * This method initializes the <code>outPushRouteTable</code> route table.
93    * It is called by the <code>getOutput</code> method. To avoid unnecessary
94    * route table, this method should test the <code>initialized</code> boolean
95    * which is set to <code>false</code> each time the router is bound to a new
96    * output.
97    */

98   protected void initRouteTable() throws PushException
99   {
100   }
101
102 }
Popular Tags