KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.dream.aggregator;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.AbstractComponent;
30 import org.objectweb.dream.Pull;
31 import org.objectweb.dream.PullException;
32 import org.objectweb.dream.message.ExtensibleMessage;
33 import org.objectweb.dream.message.Message;
34 import org.objectweb.dream.message.MessageTypeImpl;
35 import org.objectweb.dream.message.manager.MessageManager;
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.fractal.api.control.IllegalBindingException;
38 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
39
40 /**
41  * This aggregator has a pull output on which it receives pull calls requiring
42  * an aggregated message. The number of aggregated messages is specified has a
43  * context parameter of the pull call. These messages are collected on its Pull
44  * input.
45  *
46  * @see PullPullAggregatorContextualKey
47  */

48 public class PullPullAggregatorContextualImpl extends AbstractComponent
49     implements
50       Pull
51 {
52   // ---------------------------------------------------------------------------
53
// Client interfaces
54
// ---------------------------------------------------------------------------
55

56   protected Pull inPullItf;
57   protected MessageManager messageManagerItf;
58
59   // ---------------------------------------------------------------------------
60
// Implementation of the Pull interface
61
// ---------------------------------------------------------------------------
62

63   /**
64    * @see Pull#pull(Map)
65    */

66   public Message pull(Map JavaDoc context) throws PullException
67   {
68     int nbMessageToAggregate = ((Integer JavaDoc) context
69         .get(PullPullAggregatorContextualKey.KEY)).intValue();
70
71     ExtensibleMessage outMessage = (ExtensibleMessage) messageManagerItf
72         .createMessage(MessageTypeImpl.EMPTY_MESSAGE_TYPE);
73     for (int i = 0; i < nbMessageToAggregate; i++)
74     {
75       outMessage.addSubMessage(inPullItf.pull(context));
76     }
77     return outMessage;
78   }
79
80   // ---------------------------------------------------------------------------
81
// Implementation of the BindingController interface
82
// ---------------------------------------------------------------------------
83

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

87   public String JavaDoc[] listFc()
88   {
89     return new String JavaDoc[]{MessageManager.ITF_NAME, Pull.IN_PULL_ITF_NAME};
90   }
91
92   /**
93    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
94    * Object)
95    */

96   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
97       throws NoSuchInterfaceException, IllegalBindingException,
98       IllegalLifeCycleException
99   {
100     super.bindFc(clientItfName, serverItf);
101     if (clientItfName.equals(MessageManager.ITF_NAME))
102     {
103       messageManagerItf = (MessageManager) serverItf;
104     }
105     else if (clientItfName.equals(Pull.IN_PULL_ITF_NAME))
106     {
107       inPullItf = (Pull) serverItf;
108     }
109
110   }
111 }
Popular Tags