KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > protocol > utobcast > IncomingMessageRouterImpl


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.protocol.utobcast;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.AbstractComponent;
30 import org.objectweb.dream.Push;
31 import org.objectweb.dream.PushException;
32 import org.objectweb.dream.message.Message;
33 import org.objectweb.dream.protocol.utobcast.message.UTOBcastChunk;
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.fractal.api.control.IllegalBindingException;
36 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
37 import org.objectweb.util.monolog.api.BasicLevel;
38
39 /**
40  * Implementation of the IncomingMessageRouter component. This component routes
41  * incoming messages on one of its outputs. These outputs correspond to the
42  * different types of messages that can be exchanged (i.e. DAT, ACK, REP, UTO,
43  * UPD, BAK).
44  */

45 public class IncomingMessageRouterImpl extends AbstractComponent
46     implements
47       Push
48 {
49
50   // ---------------------------------------------------------------------------
51
// Fields of this class
52
// ---------------------------------------------------------------------------
53

54   /** The outputs. */
55   protected Push[] outPushItfs = new Push[6];
56
57   // ---------------------------------------------------------------------------
58
// Constructor
59
// ---------------------------------------------------------------------------
60

61   /**
62    * Constructor.
63    */

64   public IncomingMessageRouterImpl()
65   {
66   }
67
68   // ---------------------------------------------------------------------------
69
// Implementation of the Push interface
70
// ---------------------------------------------------------------------------
71

72   /**
73    * @see org.objectweb.dream.Push#push(org.objectweb.dream.message.Message,
74    * java.util.Map)
75    */

76   public void push(Message message, Map JavaDoc context) throws PushException
77   {
78     // TODO Auto-generated method stub
79
UTOBcastChunk chunk = (UTOBcastChunk) message
80         .getChunk(UTOBcastChunk.DEFAULT_NAME);
81     if (chunk == null)
82     {
83       logger.log(BasicLevel.ERROR,
84           "The message does not contain an UTOBcast chunk:" + message);
85       throw new PushException("The message does not contain an UTOBcast chunk:"
86           + message);
87     }
88     outPushItfs[chunk.getUTOBcastMessageType()].push(message, null);
89   }
90
91   // ---------------------------------------------------------------------------
92
// Implementation of the BindingController interface
93
// ---------------------------------------------------------------------------
94

95   /**
96    * @see org.objectweb.fractal.api.control.BindingController#bindFc(java.lang.String,
97    * java.lang.Object)
98    */

99   public void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
100       throws NoSuchInterfaceException, IllegalBindingException,
101       IllegalLifeCycleException
102   {
103     super.bindFc(clientItfName, serverItf);
104     if (clientItfName.endsWith("DAT"))
105     {
106       outPushItfs[UTOBcastChunk.DAT] = (Push) serverItf;
107     }
108     else if (clientItfName.endsWith("ACK"))
109     {
110       outPushItfs[UTOBcastChunk.ACK] = (Push) serverItf;
111     }
112     else if (clientItfName.endsWith("REP"))
113     {
114       outPushItfs[UTOBcastChunk.REP] = (Push) serverItf;
115     }
116     else if (clientItfName.endsWith("UTO"))
117     {
118       outPushItfs[UTOBcastChunk.UTO] = (Push) serverItf;
119     }
120     else if (clientItfName.endsWith("UPD"))
121     {
122       outPushItfs[UTOBcastChunk.UPD] = (Push) serverItf;
123     }
124     else if (clientItfName.endsWith("BAK"))
125     {
126       outPushItfs[UTOBcastChunk.BAK] = (Push) serverItf;
127     }
128   }
129
130   /**
131    * @see org.objectweb.fractal.api.control.BindingController#bindFc(java.lang.String,
132    * java.lang.Object)
133    */

134   public void unbindFc(String JavaDoc clientItfName) throws NoSuchInterfaceException,
135       IllegalBindingException, IllegalLifeCycleException
136   {
137     super.unbindFc(clientItfName);
138     if (clientItfName.endsWith("DAT"))
139     {
140       outPushItfs[UTOBcastChunk.DAT] = null;
141     }
142     else if (clientItfName.endsWith("ACK"))
143     {
144       outPushItfs[UTOBcastChunk.ACK] = null;
145     }
146     else if (clientItfName.endsWith("REP"))
147     {
148       outPushItfs[UTOBcastChunk.REP] = null;
149     }
150     else if (clientItfName.endsWith("UTO"))
151     {
152       outPushItfs[UTOBcastChunk.UTO] = null;
153     }
154     else if (clientItfName.endsWith("UPD"))
155     {
156       outPushItfs[UTOBcastChunk.UPD] = null;
157     }
158     else if (clientItfName.endsWith("BAK"))
159     {
160       outPushItfs[UTOBcastChunk.BAK] = null;
161     }
162   }
163
164   /**
165    * @see org.objectweb.fractal.api.control.BindingController#listFc()
166    */

167   public String JavaDoc[] listFc()
168   {
169     String JavaDoc[] tab = new String JavaDoc[outPushItfs.length];
170     tab[0] = Push.OUT_PUSH_ITF_NAME + "-DAT";
171     tab[1] = Push.OUT_PUSH_ITF_NAME + "-ACK";
172     tab[2] = Push.OUT_PUSH_ITF_NAME + "-REP";
173     tab[3] = Push.OUT_PUSH_ITF_NAME + "-UTO";
174     tab[4] = Push.OUT_PUSH_ITF_NAME + "-UPD";
175     tab[5] = Push.OUT_PUSH_ITF_NAME + "-BAK";
176     return tab;
177   }
178
179 }
Popular Tags