Initial commit from SVN.
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
package com.de22.test.multiuser.application;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.orb.Orb;
|
||||
import com.common.thread.*;
|
||||
import com.common.util.*;
|
||||
import com.de22.orb.Address;
|
||||
import com.de22.orb.optional.*;
|
||||
import com.foundation.util.*;
|
||||
import com.foundation.view.*;
|
||||
import com.foundation.controller.*;
|
||||
import com.foundation.application.Application;
|
||||
import com.foundation.tcv.controller.IThinServerController;
|
||||
import com.foundation.tcv.server.controller.ApplicationBrowserService;
|
||||
import com.foundation.tcv.server.controller.IInitialViewFactory;
|
||||
import com.foundation.view.resource.ResourceService;
|
||||
import com.foundation.view.swt.SwtViewContext;
|
||||
|
||||
/**
|
||||
* Simple test application that allows multiple users to type in two numbers that cannot be equal.
|
||||
* This app shows off what happens when two people try to modify the same data at the same time.
|
||||
*/
|
||||
public class TestMultiUserApplication extends Application {
|
||||
/** The property name that determines whether we generate proxies. This should only be true during development. */
|
||||
private static final String PROPERTY_GENERATE_PROXIES = "generate.proxies";
|
||||
/** The property name that gives us the ip:port for starting the server socket listener. */
|
||||
private static final String PROPERTY_SERVER_ADDRESS = "server.address";
|
||||
|
||||
private static final String SERVER_SOCKET_NAME = "testApplicationServerSocket";
|
||||
private static final Object THIN_VIEW_PERMISSION = new Object();
|
||||
private static final String APPLICATION_NAME = "Unlicensed.SampleApplication";
|
||||
private static final TestMultiUserApplication singleton = new TestMultiUserApplication();
|
||||
/**
|
||||
* Starts the Foundation Multi User Test Application application.
|
||||
* @param args None expected.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
getSingleton().startup();
|
||||
getSingleton().waitForShutdown();
|
||||
}//main()//
|
||||
/**
|
||||
* Gets the one and only instance of the application.
|
||||
* @return The singleton instance.
|
||||
*/
|
||||
public static TestMultiUserApplication getSingleton() {
|
||||
return singleton;
|
||||
}//getSingleton()//
|
||||
/**
|
||||
* TestMultiUserApplication constructor.
|
||||
*/
|
||||
public TestMultiUserApplication() {
|
||||
super();
|
||||
}//TestMultiUserApplication()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#getDefaultRepositoryIdentifier()
|
||||
*/
|
||||
public Object getDefaultRepositoryIdentifier() {
|
||||
return null;
|
||||
}//getDefaultRepositoryIdentifier()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#getMetadataLocation()
|
||||
*/
|
||||
public Object getMetadataLocation() {
|
||||
return "metadata.xml";
|
||||
}//getMetadataLocation()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#initializeResources(com.foundation.view.resource.ResourceService)
|
||||
*/
|
||||
protected void initializeResources(ResourceService resourceService) {
|
||||
}//initializeResources()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#internalShutdown()
|
||||
*/
|
||||
protected void internalShutdown() {
|
||||
try {
|
||||
Orb.closeServerSocket(SERVER_SOCKET_NAME);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
SwtViewContext.getSingleton().shutdown();
|
||||
Scheduler.shutdown();
|
||||
ActiveScheduler.getSingleton().shutdown();
|
||||
|
||||
super.internalShutdown();
|
||||
}//internalShutdown()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.application.Application#startup()
|
||||
*/
|
||||
protected void startup() {
|
||||
String generateProxiesProperty = System.getProperty(PROPERTY_GENERATE_PROXIES);
|
||||
boolean generateProxies = (generateProxiesProperty != null) && ((generateProxiesProperty.equals("yes")) || (generateProxiesProperty.equals("on")) || (generateProxiesProperty.equals("true")));
|
||||
|
||||
//Setup the debug log.//
|
||||
Debug.setLog(new DefaultLog());
|
||||
//Setup the metadata service.//
|
||||
setupMetadataService();
|
||||
//Setup the resource server.//
|
||||
setupResourceService();
|
||||
//Setup the ORB.//
|
||||
Orb.setOrbWrapper(new com.de22.orb.optional.CommonOrbWrapper(generateProxies ? new com.de22.orb.development.OrbClassLoader(".\\proxies\\") : null, null, null));
|
||||
|
||||
try {
|
||||
//Start the application specific code.//
|
||||
startApplication();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
//Log all errors that are not caught earlier in the program.//
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}//startup()//
|
||||
/**
|
||||
* Starts the actual application.
|
||||
*/
|
||||
private void startApplication() {
|
||||
try {
|
||||
LiteHashSet permissionSet = new LiteHashSet(1);
|
||||
Address tcvServerAddress;
|
||||
|
||||
if(System.getProperty(PROPERTY_SERVER_ADDRESS) == null) {
|
||||
throw new IllegalArgumentException("Must provide a property named " + PROPERTY_SERVER_ADDRESS);
|
||||
}//if//
|
||||
else {
|
||||
tcvServerAddress = new Address(System.getProperty(PROPERTY_SERVER_ADDRESS));
|
||||
}//else//
|
||||
|
||||
Debug.log("Starting the remote view server on " + tcvServerAddress);
|
||||
//Create the set of permissions.//
|
||||
permissionSet.add(THIN_VIEW_PERMISSION);
|
||||
|
||||
if(Orb.openServerSocket(SERVER_SOCKET_NAME, new ServerSocketOptions(tcvServerAddress, tcvServerAddress, new SocketOptions(), null, 0, 0, null)) != null) {
|
||||
ManagedList serverAddresses = new ManagedList();
|
||||
ManagedList downloadAddresses = new ManagedList();
|
||||
ApplicationBrowserService service = new ApplicationBrowserService(this);
|
||||
|
||||
serverAddresses.add(tcvServerAddress.toString());
|
||||
|
||||
//Create the thin view controller.//
|
||||
service.registerApplication(APPLICATION_NAME, new IInitialViewFactory() {
|
||||
public RemoteViewController createInitialView(final IViewContext viewContext) {
|
||||
return new com.de22.test.multiuser.remote.view.controller.MainViewController(viewContext);
|
||||
}//createInitialView()//
|
||||
}, "0.6.0", "1.0", null, null, downloadAddresses, serverAddresses, new File("./Client Libraries"));
|
||||
|
||||
//Bind the controller to the server socket.//
|
||||
Orb.bind(Orb.getProxy(service, IThinServerController.class), IThinServerController.BOUND_NAME, null);
|
||||
}//if//
|
||||
else {
|
||||
Debug.log("Could not create a server socket on the specified ip:port");
|
||||
}//else//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e, "Unable to open the view service.");
|
||||
}//catch//
|
||||
|
||||
try {
|
||||
Debug.log("Type a character to exit the application.");
|
||||
System.in.read();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//startApplication()//
|
||||
}//TestMultiUserApplication//
|
||||
Reference in New Issue
Block a user