KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > aggregator > PullPullAggregatorCollectionInputImpl


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.aggregator;
26
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.objectweb.dream.AbstractComponent;
32 import org.objectweb.dream.Pull;
33 import org.objectweb.dream.PullException;
34 import org.objectweb.dream.message.ExtensibleMessage;
35 import org.objectweb.dream.message.Message;
36 import org.objectweb.dream.message.MessageTypeImpl;
37 import org.objectweb.dream.message.manager.MessageManager;
38 import org.objectweb.fractal.api.NoSuchInterfaceException;
39 import org.objectweb.fractal.api.control.IllegalBindingException;
40 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
41
42 /**
43  * This aggregator has a collection of pull inputs, and a pull output. When a
44  * message is pulled on the ouput, the aggregator pulls messages on its input,
45  * aggregates them, and returns the aggregated message. Messages received on
46  * inputs, are pulled sequencialy in a non predictible order. Input pull
47  * interfaces can return <code>null</code>. Context passed on the output pull
48  * interface is transmited to input pull interfaces.
49  */

50 public class PullPullAggregatorCollectionInputImpl extends AbstractComponent
51     implements
52       Pull
53 {
54
55   private Map JavaDoc inPullItfs = new HashMap JavaDoc();
56
57   /** the message manager client interface of this component */
58   protected MessageManager messageManagerItf;
59
60   /**
61    * @see Pull#pull(Map)
62    */

63   public Message pull(Map JavaDoc context) throws PullException
64   {
65     ExtensibleMessage outMessage = null;
66     outMessage = (ExtensibleMessage) messageManagerItf
67         .createMessage(MessageTypeImpl.EMPTY_MESSAGE_TYPE);
68     Iterator JavaDoc iter = inPullItfs.values().iterator();
69     while (iter.hasNext())
70     {
71       Pull pullItf = (Pull) iter.next();
72       Message msg = pullItf.pull(context);
73       if (msg != null)
74       {
75         outMessage.addSubMessage(msg);
76       }
77     }
78     return outMessage;
79   }
80
81   // ---------------------------------------------------------------------------
82
// Implementation of BindingController interface
83
// ---------------------------------------------------------------------------
84

85   /**
86    * @see org.objectweb.fractal.api.control.BindingController#listFc()
87    */

88   public String JavaDoc[] listFc()
89   {
90     String JavaDoc[] tab = new String JavaDoc[inPullItfs.size() + 1];
91     inPullItfs.keySet().toArray(tab);
92     tab[inPullItfs.size()] = MessageManager.ITF_NAME;
93     return tab;
94   }
95
96   /**
97    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
98    * Object)
99    */

100   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
101       throws NoSuchInterfaceException, IllegalBindingException,
102       IllegalLifeCycleException
103   {
104     super.bindFc(clientItfName, serverItf);
105     if (clientItfName.startsWith(IN_PULL_ITF_NAME))
106     {
107       inPullItfs.put(clientItfName, serverItf);
108     }
109     else if (clientItfName.equals(MessageManager.ITF_NAME))
110     {
111       messageManagerItf = (MessageManager) serverItf;
112     }
113   }
114
115   /**
116    * @see org.objectweb.fractal.api.control.BindingController#unbindFc(String)
117    */

118   public synchronized void unbindFc(String JavaDoc clientItfName)
119       throws NoSuchInterfaceException, IllegalBindingException,
120       IllegalLifeCycleException
121   {
122     super.unbindFc(clientItfName);
123     if (clientItfName.startsWith(IN_PULL_ITF_NAME))
124     {
125       inPullItfs.remove(clientItfName);
126     }
127   }
128 }
Popular Tags