com.googlecode.mobilityrpc.session.impl
Class SessionClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by com.googlecode.mobilityrpc.session.impl.SessionClassLoader

public class SessionClassLoader
extends ClassLoader

Author:
Niall Gallagher

Constructor Summary
SessionClassLoader(MobilityControllerInternal mobilityController, UUID sessionId)
           
 
Method Summary
protected  Class<?> findClass(String name)
          Tries to find classes by requesting bytecode from remote machines.
protected  URL findResource(String name)
          Tries to find resources by requesting requesting from remote machines.
protected  Enumeration<URL> findResources(String name)
          Finds resources with the given name which are loadable by this session class loader.
 void processResourceResponse(ResourceResponse resourceResponse)
          Called by the thread processing an incoming ResourceResponse object.
 void setThreadLocalConnectionId(ConnectionId connectionId)
          Called by threads processing an execution request from a remote machine, to indicate to this class loader that should those threads require classes to be loaded that the class loader can request those classes from the remote machine indicated.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionClassLoader

public SessionClassLoader(MobilityControllerInternal mobilityController,
                          UUID sessionId)
Method Detail

setThreadLocalConnectionId

public void setThreadLocalConnectionId(ConnectionId connectionId)
Called by threads processing an execution request from a remote machine, to indicate to this class loader that should those threads require classes to be loaded that the class loader can request those classes from the remote machine indicated.

When threads finish processing execution requests, they should call this method supplying null for the connection id.

Parameters:
connectionId - Indicates the current connection in use by a thread processing an execution request

processResourceResponse

public void processResourceResponse(ResourceResponse resourceResponse)
Called by the thread processing an incoming ResourceResponse object. This method will look up and unblock the relevant thread which is waiting for the resource to arrive.

Parameters:
resourceResponse - Contains class bytecode or other resource which this class loader previously requested from a remote machine on behalf of a thread on this machine which tried to access a class/resource which was not loaded.

findClass

protected Class<?> findClass(String name)
                      throws ClassNotFoundException
Tries to find classes by requesting bytecode from remote machines. This method will be called by the superclass implementation of ClassLoader.loadClass(java.lang.String) when the parent class loader cannot locate the required class according to the parent delegation model of class loading.

Overrides:
findClass in class ClassLoader
Parameters:
name - The binary name of the class required
Returns:
The requested class, freshly loaded into the local JVM by requesting its bytecode from a remote machine
Throws:
ClassNotFoundException - If the requested class cannot be located on remote machines

findResource

protected URL findResource(String name)
Tries to find resources by requesting requesting from remote machines. This method will be called by the superclass implementation of ClassLoader.getResource(String) when the parent class loader cannot locate the required resource according to the parent delegation model of class loading.

This method caches all resources loaded from client machines, and will serve from this cache whenever possible.

The URL.openStream() method of the URL returned, will provide the resource data.

The toString representation of the URL will resemble the following:
mobility-rpc://[192.168.56.1:52671:0]/5f088ec8-4f71-4fae-a89b-56a0b408dcbe/test-resource.txt (when referencing a remote machine)
mobility-rpc://[local-cache:0:0]/5f088ec8-4f71-4fae-a89b-56a0b408dcbe/test-resource.txt (when subsequently cached locally)
Note that the string representation is for debugging purposes only. The JVM will not be able to parse the URL from this string. The URL object returned however, is able to provide the binary content of the resource.

Overrides:
findResource in class ClassLoader
Parameters:
name - The name of the resource required
Returns:
A URL whose URL.openStream() method provides content for the given resource. Returns null if the resource could not be found

findResources

protected Enumeration<URL> findResources(String name)
Finds resources with the given name which are loadable by this session class loader.

This will return either one URL or zero URLs. This method delegates to findResource(String).

Overrides:
findResources in class ClassLoader
Parameters:
name - The name of the resource
Returns:
either one URL or zero URLs providing access to a resource with the given name


Copyright © 2016. All rights reserved.