Source code: jacomma/examples/Mobile.java
1 /*
2 * $Source: /home/data/cvsroot/src/jacomma/examples/Mobile.java,v $
3 * $Revision: 1.5 $
4 * $Date: 2000/10/28 20:09:07 $
5 *
6 * This file is part of the jacomma framework
7 * Copyright (c) 2000 Dimitrios Vyzovitis
8 * mailto:dviz@egnatia.ee.auth.gr
9 *
10 *
11 *
12 *
13 *
14 *
15 * This library is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU Library General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU Library General Public License for more details.
24 *
25 * You should have received a copy of the GNU Library General Public License
26 * along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330,
28 * Boston, MA 02111-1307 USA
29 */
30
31 package jacomma.examples;
32
33 import jacomma.platform.core.*;
34 import jacomma.icm.type.*;
35
36 import java.util.List;
37 import java.util.ArrayList;
38 import java.net.InetAddress;
39
40 /**
41 * TBA
42 **/
43 public class Mobile extends AgentObserverAdapter {
44
45 java.util.List list_ = new java.util.ArrayList();
46 java.util.Properties prop_ = new java.util.Properties();
47
48 public Mobile(){}
49
50 public void addHandler( MessagePattern p, Agent.MessageHandler h ) {
51 list_.add( p );
52 list_.add( h );
53 }
54
55 public void setProperty( String key, Object p ) {
56 prop_.put( key, p );
57 }
58
59 public void onRegisteredAgent( Agent ag, InetAddress at ) {
60 System.out.println( ag + " has been spawned. Initializing at " + at );
61 for ( java.util.Iterator it = list_.iterator();
62 it.hasNext();
63 ag.registerHandler( (MessagePattern)it.next(),
64 (Agent.MessageHandler)it.next() ) );
65 ag.properties().putAll( prop_ );
66
67 System.out.println( ag + " has been initialized." );
68 }
69
70 public static List makeRequest( Symbol perf, String name, Mobile mob ) {
71 List l = new ArrayList();
72 l.add( perf );
73 l.add( name );
74 l.add( mob );
75
76 return l;
77 }
78
79 }