// First, register any MBeans. We do this before we start accepting
// connections from the clients to ease testing of JMX (DERBY-3689).
// This way we know that once we can connect to the network server,
// the MBeans will be available.
ManagementService mgmtService = ((ManagementService)
Monitor.getSystemModule(Module.JMX));
final Object versionMBean = mgmtService.registerMBean(
new Version(
getNetProductVersionHolder(),
SystemPermission.SERVER),
VersionMBean.class,
"type=Version,jar=derbynet.jar");
final Object networkServerMBean = mgmtService.registerMBean(
new NetworkServerMBeanImpl(this),
NetworkServerMBean.class,
"type=NetworkServer");
// We accept clients on a separate thread so we don't run into a problem
// blocking on the accept when trying to process a shutdown
final ClientThread clientThread =
(ClientThread) AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws Exception
{
return new ClientThread(thisControl,
serverSocket);
}
}
);
clientThread.start();
try {
// wait until we are told to shutdown or someone sends an InterruptedException
synchronized(shutdownSync) {
try {
while (!shutdown) {
shutdownSync.wait();
}
}
catch (InterruptedException e)
{
shutdown = true;
}
}
try {
AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
// Need to interrupt the memcheck thread if it is sleeping.
if (mc != null)
mc.interrupt();
//interrupt client thread
clientThread.interrupt();
return null;
}
});
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
// Close out the sessions
synchronized(sessionTable) {
for (Enumeration e = sessionTable.elements(); e.hasMoreElements(); )
{
Session session = (Session) e.nextElement();
try {
session.close();
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
}
}
synchronized (threadList)
{
//interupt any connection threads still active
for (int i = 0; i < threadList.size(); i++)
{
try {
final DRDAConnThread threadi = (DRDAConnThread)threadList.get(i);
threadi.close();
AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
threadi.interrupt();
return null;
}
});
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
}
threadList.clear();
}
// close the listener socket
try{
serverSocket.close();
}catch(IOException e){
consolePropertyMessage("DRDA_ListenerClose.S", true);
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
// Wake up those waiting on sessions, so
// they can close down
try{
synchronized (runQueue) {
runQueue.notifyAll();
}
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
// And now unregister any MBeans.
try {
mgmtService.unregisterMBean(versionMBean);
mgmtService.unregisterMBean(networkServerMBean);
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
if (shutdownDatabasesOnShutdown) {