Qwylt

java.lang.module.spi
Class SharedState

java.lang.Object
  extended by java.lang.module.spi.SharedState

public abstract class SharedState
extends java.lang.Object

A holder for state that is shared by a set of archives that must share a ClassLoader.

Since:
Feb 3, 2009
Author:
Bryan Atsatt

Constructor Summary
protected SharedState(java.util.List<? extends ModuleArchive> compositeMembers)
          Constructs an instance for the specified composite members.
protected SharedState(ModuleRepository repository)
          Constructs an empty instance on which load() should be called.
 
Method Summary
protected abstract  java.lang.ClassLoader createLoader(ClassSpace imports, java.util.List<? extends ModuleArchive> members)
          Creates a ClassLoader to be shared by the composite members.
 java.lang.ClassLoader getClassLoader()
          Returns the ClassLoader that should be shared by all composite members.
 java.util.List<? extends ModuleArchive> getCompositeMembers()
          Returns the composite members.
 java.util.Set<java.lang.String> getExports()
          Returns the combined exports of the composite members.
 java.util.Set<ModuleArchive> getImported(ModuleArchive importer)
          Returns the imported and member archives.
 ImportSpace getImports()
          Returns the combined imports of the composite members.
 ModuleArchive getRootMember()
          Returns the root member.
 boolean load(Streams.In in)
          Load this instance from the specified stream.
protected  java.util.Set<java.lang.String> mergeExports(java.util.List<? extends ModuleArchive> members)
          Merges the exports of the composite members.
protected  ImportSpace mergeImports(java.util.List<? extends ModuleArchive> members)
          Merges the imports of the composite members.
 void store(Streams.Out out)
          Store this instance into the specified stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SharedState

protected SharedState(ModuleRepository repository)
Constructs an empty instance on which load() should be called.


SharedState

protected SharedState(java.util.List<? extends ModuleArchive> compositeMembers)
Constructs an instance for the specified composite members.

Parameters:
compositeMembers - The set of composite members.
Throws:
java.lang.IllegalStateException - if the set is empty or if any of the members are not composites.
Method Detail

getRootMember

public ModuleArchive getRootMember()
Returns the root member.

Returns:
the root member.

getCompositeMembers

public java.util.List<? extends ModuleArchive> getCompositeMembers()
Returns the composite members.

Returns:
An unmodifiable list of the composite members.

getImports

public ImportSpace getImports()
Returns the combined imports of the composite members.

Returns:
The imports.
Throws:
java.lang.IllegalStateException - if this instance is not connected.

getExports

public java.util.Set<java.lang.String> getExports()
Returns the combined exports of the composite members.

Returns:
The exports.
Throws:
java.lang.IllegalStateException - if this instance is not connected.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the ClassLoader that should be shared by all composite members.

Returns:
The class loader.

getImported

public java.util.Set<ModuleArchive> getImported(ModuleArchive importer)
Returns the imported and member archives.

Parameters:
importer - The importer to filter out of the result.
Returns:
The archives.

store

public void store(Streams.Out out)
           throws java.io.IOException
Store this instance into the specified stream.

Parameters:
out - The stream.
Throws:
java.io.IOException - If a failure occurs.

load

public boolean load(Streams.In in)
             throws java.io.IOException
Load this instance from the specified stream.

Parameters:
in - The stream.
Returns:
true if result is valid, false if the data is out of sync.
Throws:
java.io.IOException - If a failure occurs.

mergeImports

protected ImportSpace mergeImports(java.util.List<? extends ModuleArchive> members)
Merges the imports of the composite members. This implementation will return the union of the imports of all members; subclasses may override to change this behavior.

Parameters:
members - The composite members.
Returns:
The merged imports.

mergeExports

protected java.util.Set<java.lang.String> mergeExports(java.util.List<? extends ModuleArchive> members)
Merges the exports of the composite members. This implementation will return the union of the exports of all members; subclasses may override to change this behavior.

Parameters:
members - The composite members.
Returns:
The merged exports.

createLoader

protected abstract java.lang.ClassLoader createLoader(ClassSpace imports,
                                                      java.util.List<? extends ModuleArchive> members)
Creates a ClassLoader to be shared by the composite members.

Parameters:
imports - The merged imports.
members - The composite members.
Returns:
The class loader.

Qwylt

Send comments or questions to Bryan Atsatt