use of org.apache.derby.mbeans.Version in project derby by apache.
the class NetworkServerControlImpl method blockingStart.
/**
* Start a network server
*
* @param consoleWriter PrintWriter to which server console will be
* output. Null will disable console output.
*
* @exception Exception throws an exception if an error occurs
*/
public void blockingStart(PrintWriter consoleWriter) throws Exception {
startNetworkServer();
setLogWriter(consoleWriter);
cloudscapeLogWriter = Monitor.getStream().getPrintWriter();
if (SanityManager.DEBUG && debugOutput) {
memCheck.showmem();
mc = new memCheck(200000);
mc.start();
}
// Open a server socket listener
try {
serverSocket = AccessController.doPrivileged(new PrivilegedExceptionAction<ServerSocket>() {
public ServerSocket run() throws IOException {
return createServerSocket();
}
});
} catch (PrivilegedActionException e) {
Exception e1 = e.getException();
// throws an exception when the severity is S (or U).
if (e1 instanceof UnknownHostException) {
consolePropertyMessage("DRDA_UnknownHost.S", hostArg);
} else if (e1 instanceof IOException) {
consolePropertyMessage("DRDA_ListenPort.S", new String[] { Integer.toString(portNumber), hostArg, // string to the user.
e1.toString() });
} else {
throw e1;
}
} catch (Exception e) {
// If we find other (unexpected) errors, we ultimately exit--so make
// sure we print the error message before doing so (Beetle 5033).
throwUnexpectedException(e);
}
switch(getSSLMode()) {
default:
case SSL_OFF:
consolePropertyMessage("DRDA_Ready.I", new String[] { Integer.toString(portNumber), att_srvclsnm, versionString });
break;
case SSL_BASIC:
consolePropertyMessage("DRDA_SSLReady.I", new String[] { Integer.toString(portNumber), att_srvclsnm, versionString });
consolePropertyMessage("DRDA_EnabledProtocols.I", new String[] { getEnabledProtocols((SSLServerSocket) serverSocket), att_srvclsnm, versionString });
break;
case SSL_PEER_AUTHENTICATION:
consolePropertyMessage("DRDA_SSLClientAuthReady.I", new String[] { Integer.toString(portNumber), att_srvclsnm, versionString });
consolePropertyMessage("DRDA_EnabledProtocols.I", new String[] { getEnabledProtocols((SSLServerSocket) serverSocket), att_srvclsnm, versionString });
break;
}
// 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) 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 = AccessController.doPrivileged(new PrivilegedExceptionAction<ClientThread>() {
public ClientThread 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<Void>() {
public Void 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 (Session session : sessionTable.values()) {
try {
session.close();
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
}
}
synchronized (threadList) {
// interupt any connection threads still active
for (final DRDAConnThread threadi : threadList) {
try {
threadi.close();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void 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);
}
// 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) {
// Shutdown Derby
try {
// tell driver to shutdown the engine
if (cloudscapeDriver != null) {
// DERBY-2109: pass user credentials for driver shutdown
final Properties p = new Properties();
if (userArg != null) {
p.setProperty("user", userArg);
}
if (passwordArg != null) {
p.setProperty("password", passwordArg);
}
// DERBY-6224: DriverManager.deregisterDriver() requires
// an extra permission in JDBC 4.2 and later. Invoke
// system shutdown with deregister=false to avoid the
// need for the extre permission in the default server
// policy. Since the JVM is about to terminate, we don't
// care whether the JDBC driver is deregistered.
cloudscapeDriver.connect("jdbc:derby:;shutdown=true;deregister=false", p);
}
} catch (SQLException sqle) {
// If we can't shutdown Derby, perhaps, authentication has
// failed or System Privileges weren't granted. We will just
// print a message to the console and proceed.
String expectedState = StandardException.getSQLStateFromIdentifier(SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
if (!expectedState.equals(sqle.getSQLState())) {
consolePropertyMessage("DRDA_ShutdownWarning.I", sqle.getMessage());
}
} catch (Exception exception) {
consolePrintAndIgnore("DRDA_UnexpectedException.S", exception, true);
}
}
consolePropertyMessage("DRDA_ShutdownSuccess.I", new String[] { att_srvclsnm, versionString });
} catch (Exception ex) {
try {
// If the console printing is not available, then we have
// a simple stack trace print below to atleast print some
// exception info
consolePrintAndIgnore("DRDA_UnexpectedException.S", ex, true);
} catch (Exception e) {
}
ex.printStackTrace();
}
}
use of org.apache.derby.mbeans.Version in project derby by apache.
the class JMXManagementService method boot.
/**
* Start the management service if derby.system.jmx is true.
* <P>
* Starting the service means:
* <UL>
* <LI> getting the platform MBeanServer which may require starting it
* <LI> registering a Version mbean representing the system
* </UL>
*/
public synchronized void boot(boolean create, Properties properties) throws StandardException {
registeredMbeans = new HashMap<ObjectName, StandardMBean>();
systemIdentifier = getMonitor().getUUIDFactory().createUUID().toString();
findServer();
myManagementBean = (ObjectName) registerMBean(this, ManagementMBean.class, "type=Management");
myManagementServer = mbeanServer;
registerMBean(new Version(getMonitor().getEngineVersion(), SystemPermission.ENGINE), VersionMBean.class, "type=Version,jar=derby.jar");
}
Aggregations