The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

DCOM Question

When my DCOM client releases the final reference, the remote object is not dying immediately. I want to wait to make sure that my remote object is actually terminated before I continue in the client application.

Is there any straightforward way to achieve this?
EX_MS
Tuesday, November 23, 2004
 
 
You don't need to wait until your remote object terminates. Use the state pattern to control the remote object state.

In Java ...

interface Service {
  void initialize() throws StateException;
  void shutdown() throws StateException;
  void do() throws ServiceException;
}

class AService implements Service, RemoteUnicastObject {

  interface State {
      void do() throws ServiceException;
  }
 
  class InitializingState implements State {
      void do() throws ServiceException {
        // inherited from ServiceException
        throw new InitializingException() ;
      }
  }

  class NotRunningState implements State {
      void do() throws ServiceException{
        // inherited from ServiceException
        throw new NotRunningException();
      }
  }

  class RunningState implements State {
      void do() throws ServiceException { ... }


  class ShuttingDown implements State {
      void do() throws ServiceException {
        // Inherited from ServiceException
        throw new ShuttingDownException();
      }
  }

  State objState = new NotRunningState();

  void initialize() throws StateException {
      synchronized(objState) {
        if(!(objState instanceof NotRunningState))
                throw new AlreadyRunningException();
          objState = new InitializingState();
        }

        // Your initializing code below
            ...

      synchronized(objState) {
          objState = new RunningState();
      }
  }

  void shutdown() throws StateException {
      synchronized(objState) {
        if(!(objState instanceof RunningState) ||
            !(objState instanceof InitializingState))
                throw new NotRunningException();
        objState = new ShuttingDownState();

      // Your shutdown code below
          ...

      synchronized(objState) {
          objState = new NotRunningState();
      }
  }


  void do() {
    synchronzied(objState) {
        // Long operations are problematic.
        objState.do();
    }
  }
}

Usage:

  Service aService = serviceFactory.getAService();

  // Wait until the object initializes
  aService.initialize();

  /* You need to catch exceptions for the case when the
      server shutdowns/restarts asynchronously */   
  try {
    aService.do();
  } catch (NotRunningException nre) {
      ...
  } catch (InitializingException ie) {
      ...
  } catch (ShuttingDownException sde) {
      ...
  } 
     
  // Wait until object shutdowns
  // It doesn't matter when the server object is actually
  // released since the state is notrunning after this call.
  aService.shutdown();
Dino
Tuesday, November 23, 2004
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz