public class ServerInfo implements
ServerInfoMBean
{
private String serverName = null;
private String serverId = null;
private boolean serverStarted;
private int port;
// At least one public constructor
is required
public ServerInfo( )
{
serverName = "test-server";
serverId = "test-server_1";
serverStarted = true;
port = 8072;
}
// overloaded public constructor
public ServerInfo(String serverName, String serverId, boolean
serverStarted, int
port)
{
this.serverName
= serverName ;
this.serverId
= serverId ;
this.serverStarted
= serverStarted ;
this.port
= port ;
}
// Implementating the ServerInfoMBean
public String getServerName( )
{
// get
the ServerName
return serverName;
}
public String getServerId( )
{
// get
the ServerIdentifier
return serverId;
}
public boolean isServerStarted( )
{
// check
whether the Server is Started
return serverStarted;
}
public int getPort( )
{
// get
the ServerPort
return port;
}
public void setPort(int port)
{
// Stop
the server. Set the ServerPort. Start the server.
stopService( );
this.port
= port;
startService( );
}
public void startService( )
{
System.out.println ( "Starting server.....
" ) ;
// start
the Server
System.out.println ( "Server started
successfully. " ) ;
serverStarted =true;
}
public void stopService( )
{
System.out.println ( "Stopping server.....
" ) ;
// stop
the Server
System.out.println ( "Server stopped
" ) ;
serverStarted =false;
}
// Additional methods not
exposed for management
public void restart( )
{
stopService( );
startService( );
}
}
|
|
|