Vidur,
I used to run orion from my own launcher class for the same reasons. I have
since then removed the cumbersome code. Also orion provides methods for
launching programs/application clients automatically. If possible I suggest
moving down that route instead.
Check out the <client-module> tag in orion-application.xml.
If you still want to use your own launcher class, I have included my old
source, however I haven't used it since version .9 so it may not solve your
problems. Also I never specified the -userThreads flag as you have, but I
was able to spawn new threads outside of orion without a problem. From
reading through the documentation, the userThreads switch is mainly there
for cases where new threads are spawned from within Servlets or EJBs.
I hope you find this at least somewhat useful.
Andre V
Capture Logic
<code>
package wa;
import com.evermind.server.ApplicationServer;
import wa.process.Maintenance;
public class Launcher
{
public Launcher()
{
}
public void runOrion(String[] args)
{
System.out.println("Starting Server...");
// These lines spawn threads
wa.Entity.Cache.CacheControl.StartMaintenace();
Maintenance lxMaintenance = new Maintenance(60000);
lxMaintenance.init();
lxMaintenance.start();
try
{
/*
Start orion, however I could not figure out why this
call always
returned, so I built this hack to monitor if there were any active
threads in orion's thread pool, and shut down once all of orion's
threads were closed. This was very cumbersome and I decided to
resturcture my application to eliminate the need for startup code.
*/
ApplicationServer.main(args);
System.out.println("WA Launcher: Server Started");
ThreadGroup lxTGroup = Thread.currentThread().getThreadGroup();
Thread lxCThread = Thread.currentThread();
lxCThread.setPriority(Thread.MIN_PRIORITY);
boolean lbRun = true;
while (lbRun)
{
lxCThread.sleep(1000);
ThreadGroup[] lxGA = new
ThreadGroup[lxTGroup.activeGroupCount()];
int lnCount = lxTGroup.enumerate(lxGA);
for (int i = 0; i< lnCount; i++)
{
if
(lxGA[i].getName().equalsIgnoreCase("applicationServerThreadGroup")
&&
lxGA[i].activeCount() == 0)
{
lbRun = false;
break;
}
}
}
System.out.print("Server Shutdown: ");
wa.Entity.Cache.CacheControl.StopMaintenace();
lxMaintenance.shutdown();
System.out.println("Done!");
}
catch (Exception lxE)
{
System.out.println("Unexpected Server Termination: " +
lxE.getMessage());
System.out.println("==================================================");
lxE.printStackTrace();
}
}
public static void main(String[] args)
{
System.out.println("World Adventures Server Launcher.");
Launcher launcher = new Launcher();
launcher.invokedStandalone = true;
launcher.runOrion(args);
}
private boolean invokedStandalone = false;
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Vidur Dhanda
Sent: Sunday, August 13, 2000 12:21 PM
To: Orion-Interest
Subject: REPOST: Running application code at startup
Sorry for reposting this, but it has become absolutely critical and I
would appreciate any help.
--
Hello,
Could someone please point out what I'm doing wrong. I'm sure I'm
missing something really simple here. I can't get an Orion server
to
run under program control and do some application specific
initialization. I'm inlining some simplified code and output.
Thanks,
Vidur
import javax.naming.*;
import com.evermind.server.*;
public class Server {
public static void main(String[] args) {
try {
ApplicationServer.main(new String[] {"-userThreads"});
Context ctx = new InitialContext();
ctx.lookup ("foo");
}
catch (Exception ex) {
ex.printStackTrace();
System.err.println("Exiting ...");
System.exit (0);
}
}
}
The output is:
Orion/1.1.37 initialized
javax.naming.NamingException: Not in an application scope - start
Orion
with the -userThreads switch if using user-created threads
at com.evermind.server.f9.bh(JAX)
at com.evermind.naming.i1.lookup(JAX)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at com.epistemic.km.server.Server.main(Server.java:11)
Exiting ...