KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > utobcast > IPDestinationChunkTransformerImpl


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 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.channel.IPChannelDestinationChunk;
33 import org.objectweb.dream.message.MessageTypeImpl;
34 import org.objectweb.dream.message.ChunkAlreadyExistsException;
35 import org.objectweb.dream.message.ExtensibleMessage;
36 import org.objectweb.dream.message.Message;
37 import org.objectweb.dream.message.MessageType;
38 import org.objectweb.dream.message.manager.MessageManager;
39 import org.objectweb.dream.protocol.utobcast.message.UTOBcastChunk;
40 import org.objectweb.dream.util.Error;
41 import org.objectweb.fractal.api.NoSuchInterfaceException;
42 import org.objectweb.fractal.api.control.IllegalBindingException;
43 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
44
45 import utobcast.basic.TestChunk;
46
47 /**
48  * Implementation of the IPDestinationChunkTransformer component. This component
49  * retrieves the IP address and port of the Process to which this message is
50  * intended. It then fills an IPDestinationChunk with this information.
51  *
52  * @see IPChannelDestinationChunk
53  * @see org.objectweb.dream.protocol.utobcast.message.UTOBcastChunk
54  * @see TCPProcess
55  */

56 public class IPDestinationChunkTransformerImpl extends AbstractComponent
57     implements
58       Push
59 {
60
61   Push outPushItf;
62   MessageManager messageManagerItf;
63   MessageType msgType = new MessageTypeImpl(TestChunk.DEFAULT_NAME,
64                                TestChunk.TYPE);
65   final String JavaDoc chunkName = "destination";
66
67   // ---------------------------------------------------------------------------
68
// Implementation of the Push interface
69
// ---------------------------------------------------------------------------
70

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

75   public void push(Message message, Map JavaDoc context) throws PushException
76   {
77     UTOBcastChunk utobcastChunk = (UTOBcastChunk) message
78         .getChunk(UTOBcastChunk.DEFAULT_NAME);
79     TCPProcess process = (TCPProcess) utobcastChunk.getProcessTo();
80     IPChannelDestinationChunk chunk = (IPChannelDestinationChunk) message
81         .getChunk(chunkName);
82     if (chunk == null)
83     {
84       if (message instanceof ExtensibleMessage)
85       {
86         chunk = (IPChannelDestinationChunk) messageManagerItf
87             .createChunk(IPChannelDestinationChunk.TYPE);
88         try
89         {
90           ((ExtensibleMessage) message).addChunk(chunkName,
91               IPChannelDestinationChunk.TYPE, chunk);
92         }
93         catch (ChunkAlreadyExistsException e)
94         {
95           // cannot happend
96
}
97       }
98       else
99       {
100         Error.error("Invalid message : not extensible", logger);
101       }
102     }
103     chunk.setChannelDestinationAddr(process.getInetAddress());
104     chunk.setChannelDestinationPort(process.getPort());
105     outPushItf.push(message, context);
106   }
107
108   // ---------------------------------------------------------------------------
109
// Implementation of the BindingController interface
110
// ---------------------------------------------------------------------------
111

112   /**
113    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
114    * Object)
115    */

116   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
117       throws NoSuchInterfaceException, IllegalBindingException,
118       IllegalLifeCycleException
119   {
120     super.bindFc(clientItfName, serverItf);
121     if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME))
122     {
123       outPushItf = (Push) serverItf;
124     }
125     else if (clientItfName.equals(MessageManager.ITF_NAME))
126     {
127       messageManagerItf = (MessageManager) serverItf;
128     }
129   }
130
131   /**
132    * @see org.objectweb.fractal.api.control.BindingController#listFc()
133    */

134   public String JavaDoc[] listFc()
135   {
136     return new String JavaDoc[]{Push.OUT_PUSH_ITF_NAME, MessageManager.ITF_NAME};
137   }
138
139 }
Popular Tags