KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > protocol > atomicity > AtomicRouterImpl


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): Vivien Quema
23  */

24
25 package org.objectweb.dream.protocol.atomicity;
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.fractal.api.NoSuchInterfaceException;
34 import org.objectweb.fractal.api.control.IllegalBindingException;
35 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
36
37 /**
38  * A Router that choose a route depending on the pushing thread. This component
39  * provides an interface to set the thread that is considered as the reacting
40  * thread.
41  */

42 public class AtomicRouterImpl extends AbstractComponent
43     implements
44       Push,
45       SetReactorThread
46 {
47
48   /**
49    * the name of the client interface uesd to push messages if the pushing
50    * thread is the reacting thred
51    */

52   public static final String JavaDoc OUT_REACT_PUSH_ITF_NAME = "outReactPush";
53
54   /**
55    * The name of the client interface used to push messages if the pushing
56    * thread is not the reacting thread
57    */

58   public static final String JavaDoc OUT_NOT_REACT_PUSH_ITF_NAME = "outNotReactPush";
59
60   private Push outReactPushItf;
61   private Push outNotReactPushItf;
62   private Thread JavaDoc reactorThread;
63
64   /**
65    * @see Push#push(Message, Map)
66    */

67   public void push(Message message, Map JavaDoc context) throws PushException
68   {
69     if (Thread.currentThread() == reactorThread)
70     {
71       outReactPushItf.push(message, context);
72     }
73     else
74     {
75       outNotReactPushItf.push(message, context);
76     }
77   }
78
79   /**
80    * @see SetReactorThread#setReactorThread(Thread)
81    */

82   public void setReactorThread(Thread JavaDoc reactorThread)
83   {
84     this.reactorThread = reactorThread;
85   }
86
87   // ---------------------------------------------------------------------------
88
// Implementation of BindingController interface
89
// ---------------------------------------------------------------------------
90

91   /**
92    * @see org.objectweb.fractal.api.control.BindingController#listFc()
93    */

94   public String JavaDoc[] listFc()
95   {
96     return new String JavaDoc[]{OUT_REACT_PUSH_ITF_NAME, OUT_NOT_REACT_PUSH_ITF_NAME};
97   }
98
99   /**
100    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
101    * Object)
102    */

103   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
104       throws NoSuchInterfaceException, IllegalBindingException,
105       IllegalLifeCycleException
106   {
107     super.bindFc(clientItfName, serverItf);
108     if (clientItfName.equals(OUT_REACT_PUSH_ITF_NAME))
109     {
110       outReactPushItf = (Push) serverItf;
111     }
112     else if (clientItfName.equals(OUT_NOT_REACT_PUSH_ITF_NAME))
113     {
114       outNotReactPushItf = (Push) serverItf;
115     }
116   }
117
118 }
Popular Tags