KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > activity > ServerImpl


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):
23  */

24
25 package activity;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.AbstractComponent;
30 import org.objectweb.dream.InterruptedPullException;
31 import org.objectweb.dream.Pull;
32 import org.objectweb.dream.PullException;
33 import org.objectweb.dream.message.Message;
34 import org.objectweb.dream.util.EmptyStringArray;
35 import org.objectweb.dream.util.Error;
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.util.monolog.api.BasicLevel;
38
39 /**
40  * Server component providing a pull interface. The pull method waits on
41  * <code>this</code>.
42  */

43 public class ServerImpl extends AbstractComponent implements Pull
44 {
45
46   boolean reentrant = false;
47
48   /**
49    * @see org.objectweb.dream.Pull#pull(java.util.Map)
50    */

51   public Message pull(Map JavaDoc context) throws PullException
52   {
53     if (!reentrant)
54     {
55       reentrant = true;
56       Message m = null;
57       try
58       {
59         logger.log(BasicLevel.INFO, "reentrant call");
60         m = ((Pull) weaveableC.getFcInterface(OUT_PULL_ITF_NAME)).pull(context);
61       }
62       catch (InterruptedPullException e)
63       {
64         logger.log(BasicLevel.INFO, "Wait interrupted 1");
65         throw e;
66       }
67       catch (NoSuchInterfaceException e)
68       {
69         Error.bug(logger, e);
70       }
71       reentrant = false;
72       return m;
73     }
74     else
75     {
76       synchronized (this)
77       {
78         try
79         {
80           logger.log(BasicLevel.INFO, "Waitting");
81           this.wait();
82           logger.log(BasicLevel.INFO, "End of wait");
83         }
84         catch (InterruptedException JavaDoc e)
85         {
86           logger.log(BasicLevel.INFO, "Wait interrupted 2");
87           throw new InterruptedPullException(e);
88         }
89         return null;
90       }
91     }
92   }
93
94   /**
95    * @see org.objectweb.fractal.api.control.BindingController#listFc()
96    */

97   public String JavaDoc[] listFc()
98   {
99     return EmptyStringArray.EMPTY_STRING_ARRAY;
100   }
101
102 }
Popular Tags