@Service @PerLookup public class AppClientContainer extends Object
Allows Java programs to:
newBuilder(org.glassfish.appclient.client.acc.config.TargetServer[]) and AppClientContainerBuilder),
AppClientContainerBuilder#newContainer() ,
startClient(String[]), and
stop().
Each instance of the TargetServer class passed to the newBuilder
method represents one
server, conveying its host and port number, which the ACC can use to
"bootstrap" into the server-side ORB(s). The calling
program can request to use secured communication to a server by also passing
an instance of the Security configuration class when it creates the TargetServer
object. Note that the caller prepares the TargetServer
array completely before passing it to one of the newConfig
factory methods.
The Builder implementation
does not override or augment the list of target servers using
system property values, property settings in the container configuration, etc. If such work
is necessary to find additional target servers the calling program should do it
and prepare the array of TargetServer objects accordingly.
The calling program also passes either a File or URI for the app client archive to be run or a Class object for the main class to be run as an app client.
After the calling program has created a new AppClientContainer.Builder instance
it can set optional
information to control the ACC's behavior, such as
MessageSecurityConfig objects
Once the calling program has used the builder to configure the ACC to its liking it invokes the
builder's newContainer() method.
The return type is an AppClientContainer, and by the time
newContainer returns the AppClientContainer
has invoked the app client's main method and that method has returned to the ACC.
Any new thread the client creates or any GUI work it triggers on the AWT
dispatcher thread continues independently from the thread that called newContainer.
If needed, the calling program can invoke the stop method on
the AppClientContainer to shut down the ACC-provided services.
Invoking stop does not stop any
threads the client might have started. If the calling program needs to
control such threads it should do so itself, outside the AppClientContainer
API. If the calling program does not invoke stop the ACC will
clean up automatically as the JVM exits.
A simple case in which the calling program provides an app client JAR file and a single TargetServer might look like this:
Public methods on the Builder interfaces which set configuration information return the
Builder object itself. This allows the calling program to chain together
several method invocations, such as
import org.glassfish.appclient.client.acc.AppClientContainer;(or, alternatively)
import org.glassfish.appclient.client.acc.config.TargetServer;
AppClientContainerBuilder builder = AppClientContainer.newBuilder(
new TargetServer("localhost", 3700));
AppClientContainer acc = builder.newContainer(new File("myAC.jar").toURI());
AppClientContainer acc = builder.newContainer(MyClient.class);
Then,
acc.startClient(clientArgs);
// The newContainer method returns as soon as the client's main method returns,
// even if the client has started another thread or is using the AWT event
// dispatcher thread
// At some later point, the program can synchronize with the app client in
// a user-specified way at which point it could invoke
acc.stop();
AppClientContainerBuilder builder = AppClientContainer.newBuilder(...);
builder.clientCredentials(myUser, myPass).logger(myLogger);
| Modifier and Type | Class and Description |
|---|---|
static interface |
AppClientContainer.Builder
Prescribes the exposed behavior of ACC configuration that can be
set up further, and can be used to newContainer an ACC.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
APPCLIENT_RETAIN_TEMP_FILES_PROPERTYNAME
Prop name for keeping temporary files
|
| Constructor and Description |
|---|
AppClientContainer() |
| Modifier and Type | Method and Description |
|---|---|
protected ClassLoader |
getClassLoader() |
void |
launch(String[] args) |
protected Class |
loadClass(String className) |
static AppClientContainer.Builder |
newBuilder(org.glassfish.appclient.client.acc.config.TargetServer[] targetServers)
Creates a new ACC builder object, preset with the specified
target servers.
|
void |
prepare(Instrumentation inst) |
void |
setClientMainClassName(String clientMainClassName)
Sets the name of the main class to be executed.
|
void |
startClient(String[] args) |
void |
stop()
Stops the app client container.
|
public static final String APPCLIENT_RETAIN_TEMP_FILES_PROPERTYNAME
public static AppClientContainer.Builder newBuilder(org.glassfish.appclient.client.acc.config.TargetServer[] targetServers)
targetServers - server(s) to contact during ORB bootstrappingAppClientContainer.Builder objectpublic void prepare(Instrumentation inst) throws NamingException, IOException, InstantiationException, IllegalAccessException, InjectionException, ClassNotFoundException, SAXParseException, NoSuchMethodException, UserError
protected Class loadClass(String className) throws ClassNotFoundException
ClassNotFoundExceptionprotected ClassLoader getClassLoader()
public void launch(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException, SAXParseException, InjectionException, UserError
public void stop()
Note that the calling program should not stop the ACC if there might be other threads running, such as the Swing event dispatcher thread. Stopping the ACC can shut down various services that those continuing threads might try to use.
Also note that stopping the ACC will have no effect on any thread that the app client itself might have created. If the calling program needs to control such threads it and the client code running in the threads should agree on how they will communicate with each other. The ACC cannot help with this.
public void setClientMainClassName(String clientMainClassName) throws ClassNotFoundException
Normally the ACC reads the app client JAR's manifest to get the Main-Class attribute. The calling program can override that value by invoking this method. The main class name is also useful if the calling program provides an EAR that contains multiple app clients as submodules within it; the ACC needs the calling program to specify which of the possibly several app client modules is the one to execute.
mainClassName - ClassNotFoundExceptionCopyright © 2019. All rights reserved.