Skip to content

Commit

Permalink
Make use of new cell life cycle calls
Browse files Browse the repository at this point in the history
Motivation:

Cells now provides pre and post start life cycle calls. These callbacks
are performed in the cell's thread and logging context.

Modification:

Moves initialization out of the constructor and into the life cycle
calls.

Result:

No user visible changes, except for maybe having initialization log
messages show up in the proper cell.

Target: trunk
Require-notes: no
Require-book: no
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: https://rb.dcache.org/r/8776/
  • Loading branch information
gbehrmann committed Nov 20, 2015
1 parent 290efe9 commit 5e2f86c
Show file tree
Hide file tree
Showing 27 changed files with 998 additions and 1,220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,24 @@ public class LocationManagerConnector

private final String _domain;
private final String _lm;
private final Thread _thread;
private Thread _thread;
private String _status = "disconnected";
private int _retries;

public LocationManagerConnector(String cellName, String args) throws Exception
public LocationManagerConnector(String cellName, String args) throws ExecutionException, InterruptedException
{
super(cellName, "System", args);

Args a = getArgs();
_domain = a.getOpt("domain");
_lm = a.getOpt("lm");

try {
start();
} catch (ExecutionException e) {
Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
throw Throwables.propagate(e.getCause());
}
start();
}

@Override
protected void started()
{
_thread = getNucleus().newThread(this, "TunnelConnector");
_thread.start();
}
Expand Down Expand Up @@ -206,6 +205,8 @@ public void getInfo(PrintWriter pw)
@Override
public void cleanUp()
{
_thread.interrupt();
if (_thread != null) {
_thread.interrupt();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public CellAdapter(String cellName,
* executes the auto and defined Setup context.
* (&lt;cellName&gt;Setup and "!&lt;setupContextName&gt;)
*/
public synchronized void start() throws ExecutionException, InterruptedException
public void start() throws ExecutionException, InterruptedException
{
// TODO: Temporary and imperfect workaround to tolerate duplucate start calls
if (!_startGate.isOpen()) {
Expand Down
71 changes: 38 additions & 33 deletions modules/cells/src/main/java/dmg/cells/nucleus/SystemCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,45 @@ public void run(){
_log.info("Killer done");
}
}
public SystemCell( String cellDomainName ) throws Exception
{
super(cellDomainName, "");

_nucleus = getNucleus() ;
_cellShell = new CellShell( getNucleus() ) ;
_cellShell.addCommandListener(this);
_cellShell.addCommandListener(new LogbackShell());
_cellShell.addCommandListener(new FilterShell(_nucleus.getLoggingThresholds()));
_cellShell.addCommandListener(_cellShell.new HelpCommands());
useInterpreter( false ) ;

_runtime.addShutdownHook( new TheKiller() ) ;

Thread.setDefaultUncaughtExceptionHandler(this);

try {
start();
} catch (ExecutionException e) {
Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
throw Throwables.propagate(e.getCause());
}
}

//
public SystemCell(String cellDomainName) throws ExecutionException, InterruptedException
{
super(cellDomainName, "");

_nucleus = getNucleus();
_cellShell = new CellShell(getNucleus());

start();
}

@Override
protected void startUp()
{
_cellShell.addCommandListener(this);
_cellShell.addCommandListener(new LogbackShell());
_cellShell.addCommandListener(new FilterShell(_nucleus.getLoggingThresholds()));
_cellShell.addCommandListener(_cellShell.new HelpCommands());
useInterpreter(false);

_runtime.addShutdownHook(new TheKiller());
}

@Override
protected void started()
{
Thread.setDefaultUncaughtExceptionHandler(this);
}

@Override
public void cleanUp()
{
shutdownSystem();
_log.info("Opening shutdown lock");
_shutdownLock.open();
System.exit(0);
}

//
// interface from Cell
//
public String toString(){
Expand Down Expand Up @@ -216,15 +230,6 @@ private void shutdownCells(List<String> cells, long timeout)
}
}

@Override
public void cleanUp()
{
shutdownSystem();
_log.info("Opening shutdown lock");
_shutdownLock.open();
System.exit(0);
}

@Override
public void getInfo(PrintWriter pw)
{
Expand Down
109 changes: 0 additions & 109 deletions modules/cells/src/main/java/dmg/cells/services/BatchCell.java

This file was deleted.

82 changes: 40 additions & 42 deletions modules/cells/src/main/java/dmg/cells/services/LocationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

import org.dcache.util.Args;

import static com.google.common.base.Preconditions.checkArgument;

public class LocationManager extends CellAdapter {

private static final Logger _log =
Expand Down Expand Up @@ -1199,52 +1201,48 @@ public void shutdown()
* Server Options : -strict=[yes|no] -perm=<helpFilename> -setup=<setupFile>
*
*/
public LocationManager( String name , String args )throws Exception {
public LocationManager(String name, String args) throws Exception
{
super(name, "System", args);
_args = getArgs() ;
_nucleus = getNucleus() ;
try{
int port;
InetAddress host;
if( _args.argc() < 1 ) {
throw new
IllegalArgumentException("Usage : ... [<host>] <port> [-noclient] [-clientPort=<UDP port number>]");
}
_args = getArgs();
_nucleus = getNucleus();
start();
}

if( _args.argc() == 1 ){
//
// we are a server and a client
//
port = Integer.parseInt( _args.argv(0) );
host = InetAddress.getLoopbackAddress();
_server = new Server( port , _args ) ;
_log.info("Server Setup Done") ;
}else{
port = Integer.parseInt( _args.argv(1) );
host = InetAddress.getByName( _args.argv(0) ) ;
}
if( !_args.hasOption("noclient") ){
_client = new Client( host , port , _args ) ;
_log.info("Client started");
}
} catch(IOException | IllegalArgumentException e) {
start();
kill();
throw e;
} catch(RuntimeException e){
_log.warn(e.toString(), e) ;
start();
kill();
throw e;
}
start() ;
@Override
protected void startUp() throws Exception
{
int port;
InetAddress host;
checkArgument(_args.argc() >= 1, "Usage : ... [<host>] <port> [-noclient] [-clientPort=<UDP port number>]");

if (_args.argc() == 1) {
//
// we are a server and a client
//
port = Integer.parseInt(_args.argv(0));
host = InetAddress.getLoopbackAddress();
_server = new Server(port, _args);
_log.info("Server Setup Done");
} else {
port = Integer.parseInt(_args.argv(1));
host = InetAddress.getByName(_args.argv(0));
}
if (!_args.hasOption("noclient")) {
_client = new Client(host, port, _args);
_log.info("Client started");
}
}

if(_server != null) {
_server.start();
}
}
@Override
protected void started()
{
if (_server != null) {
_server.start();
}
}

@Override
@Override
public void getInfo( PrintWriter pw ){
if( _client != null ){
pw.println( "Client\n--------") ;
Expand Down
Loading

0 comments on commit 5e2f86c

Please sign in to comment.