KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.Push;
33 import org.objectweb.dream.PushException;
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  * Basic implementation of a Push/Pull aggregator. Each pushed message is stored
44  * in an aggregated message. This aggregated message is returned by the pull
45  * method, which then creates next aggregated message to be returned.
46  */

47 public class PushPullAggregatorImpl extends AbstractComponent
48     implements
49       Push,
50       Pull
51 {
52
53   /** the message manager client interface of this component. */
54   protected MessageManager messageManagerItf;
55
56   /**
57    * The aggregated message that will be returned by the next call of the pull
58    * method.
59    */

60   protected ExtensibleMessage nextAggregatedMessage = null;
61
62   /**
63    * @see Push#push(Message, Map)
64    */

65   public synchronized void push(Message message, Map JavaDoc context)
66       throws PushException
67   {
68     if (nextAggregatedMessage == null)
69     {
70       nextAggregatedMessage = (ExtensibleMessage) messageManagerItf
71           .createMessage(MessageTypeImpl.EMPTY_MESSAGE_TYPE);
72     }
73     nextAggregatedMessage.addSubMessage(message);
74   }
75
76   /**
77    * @see Pull#pull(Map)
78    */

79   public synchronized Message pull(Map JavaDoc context) throws PullException
80   {
81     if (nextAggregatedMessage == null)
82     {
83       return (ExtensibleMessage) messageManagerItf
84           .createMessage(MessageTypeImpl.EMPTY_MESSAGE_TYPE);
85     }
86     else
87     {
88       Message msg = nextAggregatedMessage;
89       nextAggregatedMessage = null;
90       return msg;
91     }
92   }
93
94   // ---------------------------------------------------------------------------
95
// Implementation of BindingController interface
96
// ---------------------------------------------------------------------------
97

98   /**
99    * @see org.objectweb.fractal.api.control.BindingController#listFc()
100    */

101   public String JavaDoc[] listFc()
102   {
103     return new String JavaDoc[]{MessageManager.ITF_NAME};
104   }
105
106   /**
107    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
108    * Object)
109    */

110   public synchronized void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
111       throws NoSuchInterfaceException, IllegalBindingException,
112       IllegalLifeCycleException
113   {
114     super.bindFc(clientItfName, serverItf);
115     if (clientItfName.equals(MessageManager.ITF_NAME))
116     {
117       messageManagerItf = (MessageManager) serverItf;
118     }
119   }
120
121 }
Popular Tags