[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xmlblaster-devel] LOCAL not working?



Hi again,
I have also done some changes to the JXM/Embedded/JBoss service, which
makes it possible for clients running in the same JBoss/JMX server to
get access to the serverside engine global, and as an effect of that is
able to use the LOCAL in vm protocol. 

This is done through JNDI.

The embedded service creates a utility class (GlobalUtil) which holds
the engine global:

      if ( jndiName != null) {
         bind( blaster.getMain().getGlobal() );
      } // end of if ()

private void bind(org.xmlBlaster.engine.Global engineGlobal) throws
Exception{
      if ( jndiName == null) {
         return;
      } // end of if ()
      
      // Do we have JNDI at all?
      Context ctx = null;
      try {
         ctx =  new InitialContext();
      } catch (NamingException e) {
         throw new IllegalStateException("No NamingContext available,
trying to run with a jndiName in a server withouth jndi is not valid:
"+e);
      } // end of try-catch
      
      GlobalUtil gu = new GlobalUtil(engineGlobal);
      bind(ctx,jndiName,gu);

   }

The GlobalUtil holds the engine.Global as a transient variable, which
means that if its not serialized (looked up in the same VM) it will be
accessable by the client doing the lookup. The client then uses the
GlobalUtil to hanlde its global creation and cloning, so that
engine.Global will be put in its objectEntry:

   public Global newGlobal(String propertyFileName, Properties args)
throws IllegalStateException {
      Global glob = new Global(new String[]{},false,false);
      Global clone = getClone(glob);
      addEngineProperties(clone);
      addServerProperties(clone);
      loadPropertyFile(clone,propertyFileName);
      addArguments(clone,args);
      return clone;
   }

   public Global getClone(Global global) {
      Global g = global.getClone(null);
      
      Object engine = global.getObjectEntry("ServerNodeScope");
      Object eg = engine != null ? engine : engineGlobal;
      if ( eg != null) {
         g.addObjectEntry("ServerNodeScope", eg);
      } // end of if ()
      
      // Should we perhaps also clone POA???

      return g;
   }

Here's how for example the JCA adapter uses this:

      globalUtil = new GlobalUtil();
      if ( jndiName != null) {
         try {
            globalUtil = (GlobalUtil)new
InitialContext().lookup(jndiName);
         } catch (NamingException e) {
            throw new IllegalStateException("Could not lookup GlobalUtil
with JNDI " + jndiName + ": "+e);
         } // end of try-catch
      } // end of if ()

      glob = globalUtil.newGlobal( propFile,
glob.getProperty().getProperties() );

This means that if a JNDI name is specified and the lookup is done in
the same VM as the process that bound the GlobalUtil into jndi, the
global the JCA adapter uses will be able to use a LOCAL protocol to
access the server.

Any complaints about this design?

//Peter

On Wed, 2003-09-17 at 10:22, Peter Antman wrote:
> Meetings all day yesterday, but now I have something that works; but as
> far as I understand it not designed exactly the way your stuff seems to
> be heading.
> 
> Here's the deal:
> 
> You must use a Global which contains the serverside engine global in its
> ObjectEntry "ServerNodeScope". The cloning process for each
> XmlBlasterAccess instance must therefore include ServerNodeScope.
> 
> The LocalConnections is simple: look up the engine.Global, get the stuff
> you need from it and just delegate.
> 
> LocalCallbackImpl must also have access to the engine.Global. There it
> simply adds itself as an ObjectEntry with its raw adress as key. It
> implements a new interface ServerNodeScope wich the serverside callback
> expect to find in the ObjectEntry.
> 
> Here are some snippets from LocalCallbackImpl:
> 
>    public synchronized final void initialize(Global glob, String
> loginName,
>                             CallbackAddress callbackAddress,
> I_CallbackExtended cbClient) throws XmlBlasterException {
>       this.glob = (glob == null) ? Global.instance() : glob;
>       this.log = this.glob.getLog("local");
>       this.ME = "LocalCallbackImpl-" + loginName;
>       this.callbackId = "LOCAL:"+this.hashCode();
>       this.cbClient = cbClient;
>       
>       // Set this object an the engine.Global so that the server cb
> handler
>       // can find it.
>       engineGlob =
> (org.xmlBlaster.engine.Global)glob.getObjectEntry("ServerNodeScope");
>       if (engineGlob == null)
>          throw new XmlBlasterException(this.glob,
> ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "could not retreive the
> ServerNodeScope. Am I really on the server side ?");
>       
>       // Ad the driver to the "naming" store.
>       engineGlob.addObjectEntry(callbackId,this);
> 
>    }
> 
>    public String getCbAddress() throws XmlBlasterException {
>       return callbackId;
>    }
> 
>    public String[] update(String cbSessionId, MsgUnitRaw[] msgUnitArr)
> throws XmlBlasterException
>    {
>       if (msgUnitArr == null) throw new XmlBlasterException(ME,
> "Received update of null message");
>       if (log.CALL) log.call(ME, "Entering update(" + cbSessionId + ")
> of " + msgUnitArr.length + " messages");
>       
>       return cbClient.update(cbSessionId, msgUnitArr);
>    }
> 
> The serverside part is CallbackLocalDriver. Its job is to lookup the
> client part in the ObjectEntry and just delegate to it.
> 
>    public final void init(Global glob, CallbackAddress callbackAddress)
> throws XmlBlasterException {
>       this.glob = glob;
>       this.log = glob.getLog("local");
>       this.callbackAddress = callbackAddress;
>       String callbackId = callbackAddress.getRawAddress();
>       try {
>          localCallback  = ( I_LocalCallback
> )glob.getObjectEntry(callbackId);
> 
>          if ( localCallback == null) {
>             throw new XmlBlasterException(this.glob,
> ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "could not retreive the
> LocalCallbackImpl, was there really one started");
>          } // end of if ()
>          
>       }
>       catch (Throwable e) {
>          log.error(ME, "The given callback id ='" + callbackId + "' is
> invalid: " + e.toString());
>          throw new XmlBlasterException(glob,
> ErrorCode.RESOURCE_CONFIGURATION_ADDRESS, "Local-CallbackHandleInvalid",
> "The given callback Id is invalid: " + e.toString());
>       }
>    }
> 
>    public final String[] sendUpdate(MsgUnitRaw[] msgArr) throws
> XmlBlasterException
>    {
>       if (msgArr == null || msgArr.length < 1)
>          throw new XmlBlasterException(glob,
> ErrorCode.INTERNAL_ILLEGALARGUMENT, ME, "Illegal sendUpdate()
> argument");
>       if (log.TRACE) log.trace(ME, "xmlBlaster.update() to " +
> callbackAddress.getSecretSessionId());
>       
>       try {
>          return
> localCallback.update(callbackAddress.getSecretSessionId(), msgArr);
>       } catch (XmlBlasterException xmlBlasterException) {
>          
>          // WE ONLY ACCEPT ErrorCode.USER... FROM CLIENTS !
>          if (xmlBlasterException.isUser())
>             throw xmlBlasterException;
>          
>          throw new XmlBlasterException(glob,
> ErrorCode.USER_UPDATE_ERROR, ME,
>                    "Local Callback of " + msgArr.length +
>                                        " messages to client [" +
> callbackAddress.getSecretSessionId() + "] failed.",
> xmlBlasterException);
>       }
>    }
> 
> What do you say about this?
> 
> //Peter
> 
> On Mon, 2003-09-15 at 23:58, Marcel Ruff wrote:
> > Michele Laghi wrote:
> > > Hi Peter,
> > > you'r right. The implementation of the native access has not been 
> > > completed yet.
> > 
> > I have started on it but hadn't time to finish it.
> > There are probably one/two days open
> > for finishing implementation, adding testsuite and docu and a little demo client.
> > If you do it its fine, otherwise one day i will complete it.
> > The native access is to be seen in conjunction with the
> > runlevel manager to load the native client, see
> > http://www.xmlBlaster.org/xmlBlaster/doc/requirements/engine.runlevel.howto.html
> > 
> > regards
> > 
> > Marcel
> > 
> > PS: The Euro wasn't introduced in Sweden, so my
> > Kroner lying around somewhere won't be valueless :-)
> > > 
> > > Michele
> > > 
> > > 
> > > Peter Antman wrote:
> > > 
> > >> Hi,
> > >> am I right if I have found that client.protocol.local is not working, or
> > >> should it be able to get it to work (yes, I do have access to
> > >> engine.Global), but I am getting exceptions on the server callback part
> > >> (and looking into the code I get the impression that something is
> > >> missing).
> > >>
> > >> //Peter
> > > 
> > > 
> > > 
> > 
> > 
> > -- 
> > http://www.xmlBlaster.org
> -- 
> ------------------------------------------------------------
> Peter Antman	Chief Technology Officer, Development
> Technology in Media, Box 34105 100 26 Stockholm
> WWW: http://www.tim.se	WWW: http://www.backsource.org
> Email: pra at tim.se	 
> Phone: +46-(0)8-506 381 11 Mobile: +46-(0)704 20 58 11
> ------------------------------------------------------------
-- 
------------------------------------------------------------
Peter Antman	Chief Technology Officer, Development
Technology in Media, Box 34105 100 26 Stockholm
WWW: http://www.tim.se	WWW: http://www.backsource.org
Email: pra at tim.se	 
Phone: +46-(0)8-506 381 11 Mobile: +46-(0)704 20 58 11
------------------------------------------------------------