Package intf.mobile.ccacore

Examples of intf.mobile.ccacore.MobileComponentID


    if (!componentMap.containsKey(providesComponentName))
      throw new NonstandardException("Component " + providesComponentName +
             " not present in the graph");

    // retrieve componentIDs for the uses and provides side
    MobileComponentID userID =
      new MobileComponentIDClientImpl(usesComponentName,
              usesComponentHandle);
    MobileComponentID providerID =
      new MobileComponentIDClientImpl(providesComponentName,
              providesComponentHandle);
   
    // create a ConnectionID for this connection
    XCATConnectionID connID =
View Full Code Here


    MigrationInfo mInfo = new MigrationInfo(numConns);
    migrationMap.put(componentName, mInfo);
   
    for (int i = 0; i < numConns; i++) {
      XCATConnectionID connID = (XCATConnectionID) connIDs.get(i);
      MobileComponentID userID = (MobileComponentID) connID.getUser();
     
      userID.requestMigration(componentName,
            connID.getUserPortName(),
            getGSH());
    }
   
    // Wait till all users are OK with migration
    synchronized(mInfo) {
      if (mInfo.getApprovedUsers() < numConns) {
  try {
    mInfo.wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for uses sides to approve migration",
      ie);
    throw new NonstandardException("Exception when waiting for migration approval",
           ie);
  }
      }
    }

    // check if the above call was successful
    if (mInfo.getMigrationStatus() == AppCoordinatorCallback.EXCEPTION)
      throw new NonstandardException("Remote side did not approve migration");

    // Confirm to all users that provider is migrating
    for (int i = 0; i < numConns; i++) {
      XCATConnectionID connID = (XCATConnectionID) connIDs.get(i);
      MobileComponentID userID = (MobileComponentID) connID.getUser();
      userID.confirmMigration(connID.getUserPortName());
    }
   
    // Freeze the execution of the component
    MobileComponentID cid =
      new MobileComponentIDClientImpl(cInfo.getInstanceName(),
              cInfo.getInstanceHandle());
    cid.freezeComponent(getGSH());
   
    // Wait till the component sends back a notification that it is frozen
    synchronized(mInfo) {
      if (!mInfo.getIsFrozen()) {
  try {
    mInfo.wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for migration to complete",
      ie);
    throw new NonstandardException("Exception when waiting for migration to complete",
           ie);
  }
      }
    }
   
    // decrement number of outstanding frozen components
    synchronized(this) {
      outstandingFrozenComps--;
    }

    // check if the above call was successful
    if (mInfo.getMigrationStatus() == AppCoordinatorCallback.EXCEPTION)
      throw new NonstandardException("Remote component threw exception while being frozen");

    // Store the individual component state into persistent storage
    MasterStorageService mss = (MasterStorageService)
      URLToReference.createReference(masterStorageServiceURL,
             MasterStorageService.class.getName());
    String individualStorageServiceURL = mss.getIndividualStorageServiceLocation();
    String storageID = cid.storeIndividualComponentState(individualStorageServiceURL);

    // destroy the remote component
    try {
      cid.destroy();
    } catch (Exception e) {
      logger.severe("Caught exception while trying to destroy component",
        e);
      throw new NonstandardException("Caught exception while trying to destroy component",
             e);
    }

    // create a new instance of the component at the specified location
    cInfo.setInstanceLocation(targetLocation);
    createComponentInstance(cInfo);

    // retrieve the state for the migrated component
    cid.loadComponentState(individualStorageServiceURL, storageID);

    // delete state from storage service
    IndividualStorageService iss = (IndividualStorageService)
      URLToReference.createReference(individualStorageServiceURL,
             IndividualStorageService.class.getName());
    iss.deleteState(storageID);

    // resume execution of the migrated component
    cid.resumeExecution();

    // set the isFrozen false to false
    mInfo.setIsFrozen(false);

    // send a notification that all connected components that migration is complete
    for (int i = 0; i < numConns; i++) {
      XCATConnectionID connID = (XCATConnectionID) connIDs.get(i);
      MobileComponentID userID = (MobileComponentID) connID.getUser();
      userID.migrationComplete(connID.getUserPortName());     
    }

    // get rid of the entry inside migrationMap
    migrationMap.remove(componentName);
  }
View Full Code Here

    // send a request to freeze execution of all components
    long time0 = System.currentTimeMillis();
    Object[] componentList = componentMap.values().toArray();
    for (int i = 0; i < componentList.length; i++) {
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      MobileComponentID cid =
  new MobileComponentIDClientImpl(cInfo.getInstanceName(),
          cInfo.getInstanceHandle());
      cid.freezeComponent(getGSH());
    }
    long time1 = System.currentTimeMillis();
    logger.info("Freeze request: " + (time1 - time0));

    // wait till all components are frozen
    if (outstandingFrozenComps < componentList.length) {
      synchronized(this) {
  try {
    wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for component to be frozen",
      ie);
    throw new NonstandardException("Exception when waiting for component to be frozen",
           ie);
  }

  // set the number of outstanding frozen components to 0
  outstandingFrozenComps = 0;

  // check if the above call was successful
  if (checkpointStatus == AppCoordinatorCallback.EXCEPTION)
    throw new NonstandardException("Exception while freezing components");
      }
    }
    long time2 = System.currentTimeMillis();
    logger.info("Time for components to freeze: " + (time2 - time1));

    // send request to store the state of the components
    MasterStorageService mss = (MasterStorageService)
      URLToReference.createReference(masterStorageServiceURL,
             MasterStorageService.class.getName());
    for (int i = 0; i < componentList.length; i++) {
      String individualStorageServiceURL = mss.getIndividualStorageServiceLocation();
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      MobileComponentID cid =
  new MobileComponentIDClientImpl(cInfo.getInstanceName(),
          cInfo.getInstanceHandle());
      cid.appendStateToCheckpoint(individualStorageServiceURL, getGSH());
    }

    // wait till all components have stored their states
    if (numComponentsStateStored < componentList.length) {
      synchronized(this) {
  try {
    wait();
  } catch (InterruptedException ie) {
    logger.severe("Exception when waiting for components to store states",
      ie);
    throw new NonstandardException("Exception when waiting for components to store states",
           ie);
  }

  // set the number of outstanding frozen components to 0
  numComponentsStateStored = 0;

  // check if the above call was successful
  if (checkpointStatus == AppCoordinatorCallback.EXCEPTION)
    throw new NonstandardException("Exception while storing component state");
      }
    }
    long time3 = System.currentTimeMillis();
    logger.info("Storing checkpoints: " + (time3 - time2));

    // Atomically update locations of checkpoints in the database
    Hashtable oldCheckpointMap = checkpointMap;
    checkpointMap = tempCheckpointMap;
    tempCheckpointMap = new Hashtable();
    if (dburl != null) {
      // Commit component information into database
      Connection conn = null;
      try {
  // connect to the database
  conn = DriverManager.getConnection(dburl,
             dbuser,
             dbpasswd);
 
  // set autocommit to false so that all of the following is atomic
  conn.setAutoCommit(false);
      } catch (Exception e) {
  logger.severe("Error while connecting to database", e);
  throw new NonstandardException("Error while connecting to database", e);
      }

      try {
  // for every component, update the distributed_checkpoint_table
  for (int i = 0; i < componentList.length; i++) {
    ComponentInfo cInfo = (ComponentInfo) componentList[i];
    CheckpointInfo cpInfo =
      (CheckpointInfo) checkpointMap.get(cInfo.getInstanceName());

    // update the entry into the table
    // have to delete + insert since MySQL 4.0.x doesn't support
    // ON DUPLICATE KEY UPDATE
    String sqlStmt0 =
      "delete from distributed_checkpoint_table where " +
      "instance_handle = '" +  cInfo.getInstanceHandle() + "';";
    PreparedStatement stmt0 = conn.prepareStatement(sqlStmt0);
    stmt0.executeUpdate();

    String sqlStmt1 =
      "insert into distributed_checkpoint_table" +
      "(instance_handle, application_id, " +
      "individual_storage_service_url, " +
      "storage_id) values (" +
      "'" + cInfo.getInstanceHandle() + "', " +
      "'" + applicationID + "', " +
      "'" + cpInfo.getStorageServiceURL() + "', " +
      "'" + cpInfo.getStorageID() + "');";
    PreparedStatement stmt1 = conn.prepareStatement(sqlStmt1);
    stmt1.executeUpdate();
  }
   
  // commit all inserts
  conn.commit();
 
  // clean up
  conn.close();
      } catch (Exception e) {
  logger.severe("Error while trying to store checkpoint locations into database: " +
          " Trying to rollback", e);
 
  // try to rollback
  try {
    conn.rollback();
  } catch (Exception re) {
    logger.severe("Error while trying to store checkpoint locations into database: " +
      " Rollback failed", re);
    throw new NonstandardException("Error while trying to store checkpoint locations " +
           "into database: Rollback failed", re);
  }
 
  throw new NonstandardException("Error while trying to store checkpoint locations " +
               "into database: Rollback successful", e);
      }
    }

    // delete old checkpoints
    Object[] cpList = oldCheckpointMap.values().toArray();
    for (int i = 0; i < cpList.length; i++) {
      CheckpointInfo cpInfo = (CheckpointInfo) cpList[i];
      IndividualStorageService iss = (IndividualStorageService)
  URLToReference.createReference(cpInfo.getStorageServiceURL(),
               IndividualStorageService.class.getName());
      iss.deleteState(cpInfo.getStorageID());
    }

    long time4 = System.currentTimeMillis();
    logger.info("Committing checkpoints: " + (time4 - time3));

    // send a notification to components that checkpointing is complete
    for (int i = 0; i < componentList.length; i++) {
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      MobileComponentID cid =
  new MobileComponentIDClientImpl(cInfo.getInstanceName(),
          cInfo.getInstanceHandle());
      cid.unfreezeComponent();
    }
    long time5 = System.currentTimeMillis();
    logger.info("Unfreezing components: " + (time5 - time4));
  }
View Full Code Here

    // destroy all the components, if they are still alive
    Object[] componentList = componentMap.values().toArray();
    for (int i = 0; i < componentList.length; i++) {
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      MobileComponentID cid =
  new MobileComponentIDClientImpl(cInfo.getInstanceName(),
          cInfo.getInstanceHandle());
      try {
  cid.destroy();
      } catch (Exception e) {
  logger.severe("Caught exception while trying to destroy component",
          e);
  // continue since the component may be dead already
      }
    }

    // instantiate all components again
    for (int i = 0; i < componentList.length; i++) {
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      createComponentInstance(cInfo);
    }

    // load the checkpointed state
    for (int i = 0; i < componentList.length; i++) {
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      CheckpointInfo cpInfo = (CheckpointInfo) checkpointMap.get(cInfo.getInstanceName());

      MobileComponentID cid =
  new MobileComponentIDClientImpl(cInfo.getInstanceName(),
          cInfo.getInstanceHandle());
      cid.loadComponentState(cpInfo.getStorageServiceURL(),
           cpInfo.getStorageID());
    }

    // tell all components to proceed
    for (int i = 0; i < componentList.length; i++) {
      ComponentInfo cInfo = (ComponentInfo) componentList[i];
      MobileComponentID cid =
  new MobileComponentIDClientImpl(cInfo.getInstanceName(),
          cInfo.getInstanceHandle());
      cid.resumeExecution();
    }
  }
View Full Code Here

TOP

Related Classes of intf.mobile.ccacore.MobileComponentID

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.