KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > protocol > causality > OutMessageStamperImpl


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): Matthieu Leclercq
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.protocol.causality;
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.ChunkAlreadyExistsException;
33 import org.objectweb.dream.message.ExtensibleMessage;
34 import org.objectweb.dream.message.Message;
35 import org.objectweb.dream.message.manager.MessageManager;
36 import org.objectweb.dream.protocol.ArrowChunk;
37 import org.objectweb.fractal.api.NoSuchInterfaceException;
38 import org.objectweb.fractal.api.control.IllegalBindingException;
39 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
40 import org.objectweb.util.monolog.api.BasicLevel;
41
42 /**
43  * Outgoing Message stamper.
44  */

45 public class OutMessageStamperImpl extends AbstractComponent
46     implements
47       Push,
48       CausalityTransformerAttributeController
49 {
50
51   private MessageManager messageManagerItf;
52   private MatrixClock matrixClockItf;
53   private Push outPushItf;
54
55   private String JavaDoc arrowChunkName;
56   private String JavaDoc causalityChunkName;
57
58   /**
59    * @see Push#push(Message, Map)
60    */

61   public void push(Message message, Map JavaDoc context) throws PushException
62   {
63     ArrowChunk arrowChunk = (ArrowChunk) message.getChunk(arrowChunkName);
64
65     if (arrowChunk == null)
66     {
67       logger.log(BasicLevel.ERROR, "Unable to find arrow chunk named "
68           + arrowChunkName + ". The message is dropped");
69       return;
70     }
71
72     CausalityChunk csltChunk = (CausalityChunk) message
73         .getChunk(causalityChunkName);
74     if (csltChunk == null)
75     {
76       if (message instanceof ExtensibleMessage)
77       {
78         csltChunk = (CausalityChunk) messageManagerItf
79             .createChunk(CausalityChunk.TYPE);
80         try
81         {
82           ((ExtensibleMessage) message).addChunk(causalityChunkName,
83               CausalityChunk.TYPE, csltChunk);
84         }
85         catch (ChunkAlreadyExistsException e)
86         {
87           // cannot happend.
88
}
89       }
90       else
91       {
92         logger
93             .log(
94                 BasicLevel.ERROR,
95                 "Unable to find causality chunk in the unextensible message. The message is dropped");
96         return;
97       }
98     }
99     Object JavaDoc stamp = matrixClockItf.getStamp(arrowChunk.getProcessIdFrom(),
100         arrowChunk.getProcessIdTo());
101     csltChunk.setCausalityStamp(stamp);
102     outPushItf.push(message, context);
103   }
104
105   // ---------------------------------------------------------------------------
106
// Implementation of CausalityTransformerAttributeController interface
107
// ---------------------------------------------------------------------------
108

109   /**
110    * @see CausalityTransformerAttributeController#getArrowChunkName()
111    */

112   public String JavaDoc getArrowChunkName()
113   {
114     return arrowChunkName;
115   }
116
117   /**
118    * @see CausalityTransformerAttributeController#setArrowChunkName(String)
119    */

120   public void setArrowChunkName(String JavaDoc arrowChunkName)
121   {
122     this.arrowChunkName = arrowChunkName;
123   }
124
125   /**
126    * @see CausalityTransformerAttributeController#getCausalityChunkName()
127    */

128   public String JavaDoc getCausalityChunkName()
129   {
130     return causalityChunkName;
131   }
132
133   /**
134    * @see CausalityTransformerAttributeController#setCausalityChunkName(String)
135    */

136   public void setCausalityChunkName(String JavaDoc causalityChunkName)
137   {
138     this.causalityChunkName = causalityChunkName;
139   }
140
141   // ---------------------------------------------------------------------------
142
// Implementation of BindingController interface
143
// ---------------------------------------------------------------------------
144

145   /**
146    * @see org.objectweb.fractal.api.control.BindingController#listFc()
147    */

148   public String JavaDoc[] listFc()
149   {
150     return new String JavaDoc[]{Push.OUT_PUSH_ITF_NAME,
151         MatrixClock.MATRIX_CLOCK_ITF_NAME, MessageManager.ITF_NAME};
152   }
153
154   /**
155    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
156    * Object)
157    */

158   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
159       throws NoSuchInterfaceException, IllegalBindingException,
160       IllegalLifeCycleException
161   {
162     super.bindFc(clientItfName, serverItf);
163     if (clientItfName.equals(MatrixClock.MATRIX_CLOCK_ITF_NAME))
164     {
165       matrixClockItf = (MatrixClock) serverItf;
166     }
167     else if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME))
168     {
169       outPushItf = (Push) serverItf;
170     }
171     else if (clientItfName.equals(MessageManager.ITF_NAME))
172     {
173       messageManagerItf = (MessageManager) serverItf;
174     }
175   }
176
177 }
Popular Tags