KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > pushwithreturn > ConsumerImpl


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 pushwithreturn;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.AbstractComponent;
30 import org.objectweb.dream.InterruptedPushException;
31 import org.objectweb.dream.Push;
32 import org.objectweb.dream.PushException;
33 import org.objectweb.dream.message.MessageTypeImpl;
34 import org.objectweb.dream.message.Message;
35 import org.objectweb.dream.message.MessageType;
36 import org.objectweb.dream.message.manager.MessageManager;
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  * Implementation of the Consumer component.
44  */

45 public class ConsumerImpl extends AbstractComponent implements Push
46 {
47
48   Push outPushItf;
49   MessageManager messageManagerItf;
50   MessageType msgType = new MessageTypeImpl(TestChunk.DEFAULT_NAME,
51                              TestChunk.TYPE);
52
53   // ---------------------------------------------------------------------------
54
// Implementation of the Push interface
55
// ---------------------------------------------------------------------------
56

57   /**
58    * @see org.objectweb.dream.Push#push(org.objectweb.dream.message.Message,
59    * java.util.Map)
60    */

61   public void push(Message message, Map JavaDoc context) throws PushException
62   {
63     logger.log(BasicLevel.INFO, "Consumer receives message " + message);
64
65     TestChunk chunk = (TestChunk) message.getChunk(TestChunk.DEFAULT_NAME);
66     chunk.setMessage("Return message");
67
68     try
69     {
70       Thread.sleep(2000);
71     }
72     catch (InterruptedException JavaDoc e)
73     {
74       throw new InterruptedPushException(e);
75     }
76
77     logger.log(BasicLevel.INFO, "Consumer sends return message");
78
79     outPushItf.push(message, null);
80   }
81
82   // ---------------------------------------------------------------------------
83
// Implementation of the BindingController interface
84
// ---------------------------------------------------------------------------
85

86   /**
87    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
88    * Object)
89    */

90   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
91       throws NoSuchInterfaceException, IllegalBindingException,
92       IllegalLifeCycleException
93   {
94     super.bindFc(clientItfName, serverItf);
95     if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME))
96     {
97       outPushItf = (Push) serverItf;
98     }
99     else if (clientItfName.equals(MessageManager.ITF_NAME))
100     {
101       messageManagerItf = (MessageManager) serverItf;
102     }
103   }
104
105   /**
106    * @see org.objectweb.fractal.api.control.BindingController#listFc()
107    */

108   public String JavaDoc[] listFc()
109   {
110     return new String JavaDoc[]{Push.OUT_PUSH_ITF_NAME, MessageManager.ITF_NAME};
111   }
112
113 }
Popular Tags