KickJava   Java API By Example, From Geeks To Geeks.

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


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 aggregates a fixed number of messages. These messages are
42  * collected on its Pull input. The number of messages to be aggregated is set
43  * using the
44  * {@link org.objectweb.dream.aggregator.PullPullAggregatorFixedNumberAttributeController}
45  * interface.
46  */

47 public class PullPullAggregatorFixedNumberImpl extends AbstractComponent
48     implements
49       Pull,
50       PullPullAggregatorFixedNumberAttributeController
51 {
52
53   private Pull inPullItf;
54
55   /** the message manager client interface of this component */
56   protected MessageManager messageManagerItf;
57
58   private int nbMessageToAggregate;
59
60   //---------------------------------------------------------------------------
61
// Implementation of the Pull interface.
62
// ---------------------------------------------------------------------------
63
/**
64    * @see Pull#pull(Map)
65    */

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

82   /**
83    * @see org.objectweb.dream.aggregator.PullPullAggregatorFixedNumberAttributeController#getNbMessagesToAggregate()
84    */

85   public int getNbMessagesToAggregate()
86   {
87     return nbMessageToAggregate;
88   }
89
90   /**
91    * @see org.objectweb.dream.aggregator.PullPullAggregatorFixedNumberAttributeController#setNbMessagesToAggregate(int)
92    */

93   public void setNbMessagesToAggregate(int nb)
94   {
95     this.nbMessageToAggregate = nb;
96   }
97
98   // ---------------------------------------------------------------------------
99
// Implementation of the BindingController interface.
100
// ---------------------------------------------------------------------------
101

102   /**
103    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
104    * Object)
105    */

106   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
107       throws NoSuchInterfaceException, IllegalBindingException,
108       IllegalLifeCycleException
109   {
110     super.bindFc(clientItfName, serverItf);
111     if (clientItfName.equals(Pull.IN_PULL_ITF_NAME))
112     {
113       inPullItf = (Pull) serverItf;
114     }
115     else if (clientItfName.equals(MessageManager.ITF_NAME))
116     {
117       messageManagerItf = (MessageManager) serverItf;
118     }
119   }
120
121   /**
122    * @see org.objectweb.fractal.api.control.BindingController#listFc()
123    */

124   public String JavaDoc[] listFc()
125   {
126     return new String JavaDoc[]{Pull.IN_PULL_ITF_NAME, MessageManager.ITF_NAME};
127   }
128
129 }
Popular Tags