KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > distribution > RemoteAccessAC


1 /*
2   Copyright (C) 2001 Renaud Pawlak
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.distribution;
19
20
21 import java.util.*;
22 import org.apache.log4j.Logger;
23 import org.objectweb.jac.core.*;
24 import org.objectweb.jac.core.dist.*;
25 import org.objectweb.jac.util.*;
26
27 /**
28  * This aspect component implements a remote access aspect.
29  *
30  * <p>On contrary to the deployement AC, JAC do not have to be lauched
31  * in a distributed mode and the server host do not have to be
32  * registered in the topology. Hence, this aspect allows a JAC
33  * container to bind to a different namespace/aspect-space in a
34  * client/server mode.
35  *
36  * @author <a HREF="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
37  *
38  * @see RemoteAccessConf
39  * @see DeploymentRule */

40
41 public class RemoteAccessAC extends AspectComponent implements RemoteAccessConf {
42     static Logger logger = Logger.getLogger("remoteaccess");
43     static Logger loggerSerial = Logger.getLogger("serialization");
44
45     public void whenSerialized ( SerializedJacObject finalObject ) {
46     
47         loggerSerial.debug("DeploymentAC.whenSerialize");
48         NameRepository nr = (NameRepository) NameRepository.get();
49         Wrappee orgObject = (Wrappee)attr( "orgObject" );
50         String JavaDoc name = nr.getName( orgObject );
51         //if ( ! isMatchingARule( orgObject ) ) {
52
loggerSerial.debug(name + " is not matching any rule");
53         finalObject.disableForwarding();
54         Object JavaDoc[] state = ObjectState.getState(orgObject);
55         String JavaDoc[] fieldsName = (String JavaDoc[]) state[0];
56         Object JavaDoc[] fieldsValue = (Object JavaDoc[]) state[1];
57       
58         for ( int i = 0; i < fieldsName.length; i++ ) {
59             loggerSerial.debug(" serializing field "+fieldsName[i]+
60                                " - "+fieldsValue[i]);
61             finalObject.addField( fieldsName[i], fieldsValue[i] );
62         }
63          
64         /*} else {
65           DeploymentRule r = getMatchingRule( orgObject );
66           if( r != null && r.getType().equals( "dynamic client-server" ) ) {
67           finalObject.disableForwarding();
68           finalObject.setACInfos(
69           ACManager.get().getName( this ),
70           RemoteRef.create( NameRepository.get().getName( orgObject ), orgObject ) );
71           }
72           }*/

73     }
74
75     /**
76      * Fill the field values when the forwarding is disabled for this
77      * object..
78      *
79      * @param orgObject the JAC object that is being deserialized. */

80    
81     public void whenDeserialized ( SerializedJacObject orgObject ) {
82         loggerSerial.debug("DeploymentAC.whenDeserialize");
83         if ( ! orgObject.isForwarder() ) {
84             loggerSerial.debug("not a forwarder");
85             Wrappee finalObject = (Wrappee)attr("finalObject");
86             RemoteRef server;
87             if( (server = (RemoteRef) orgObject.getACInfos( ACManager.get().getName( this ) ) ) != null ) {
88                 Wrapping.wrapAll(finalObject,null,new StubWrapper(this,server));
89             } else {
90                 Iterator it = orgObject.getFields().keySet().iterator();
91                 while ( it.hasNext() ) {
92                     String JavaDoc fn = (String JavaDoc) it.next();
93                     loggerSerial.debug("setting field "+fn+" <- "+
94                                        orgObject.getField( fn ));
95                     ObjectState.setFieldValue(finalObject,fn,
96                                               ObjectState.getField(orgObject,fn) );
97                 }
98             }
99         }
100     }
101
102     /**
103      *
104      */

105    
106     public void whenCreatingRemoteAccess(Wrappee wrappee, String JavaDoc serverHost) {
107         Wrapping.wrapAll(wrappee,null,new StubWrapper(this,serverHost));
108     }
109
110     public void createRemoteAccess(String JavaDoc nameExpr,
111                                    String JavaDoc classExpr,
112                                    String JavaDoc methodExpr,
113                                    String JavaDoc serverHost) {
114         try {
115             pointcut(nameExpr, classExpr, methodExpr,
116                      StubWrapper.class.getName(),
117                      new Object JavaDoc[] {serverHost}, "invoke", null, true);
118             // pointcut( nameExpr, classExpr,
119
// "whenCreatingRemoteAccess", new Object[] {serverHost} );
120
} catch ( Exception JavaDoc e ) {
121             logger.error("createRemoteAccess: pointcut creation failed",e);
122         }
123     }
124
125 }
126
Popular Tags