Exemple #1
0
  public Reservation(String id, int price) {
    this.id = id;
    this.price = price;
    this.total = INITIAL;
    this.used = 0;

    AbstractContext context = ContextDelegator.getTopInstance();
    if (context == null) HyFlow.getLocator().register(this); // publish it now
    else context.newObject(this); // add it to context publish-set
  }
 public static void remoteLockRequest(AbstractContext context, GlobalObject key) {
   int hashCode = context.hashCode();
   pendingLocks.put(hashCode, context);
   synchronized (context) {
     try {
       Logger.debug(
           "Request remote lock for " + key + " hashcode is " + hashCode + " for " + context);
       CommunicationManager.getManager().send(key.getHome(), new LockRequest(key, true, hashCode));
       context.wait();
       Logger.debug("Request remote lock come back...");
     } catch (InterruptedException e) {
       e.printStackTrace();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   pendingLocks.remove(hashCode);
 }
 @Override
 public void run() {
   Logger.debug(key + " Retured Lock " + (success ? "granted" : "refused"));
   if (senderClock > LocalClock.get()) LocalClock.advance(senderClock);
   if (hashCode == 0) {
     Logger.debug("No call backs");
     return;
   }
   Logger.debug("Hashcode is " + hashCode);
   AbstractContext context = LockTable.pendingLocks.get(hashCode);
   if (context == null) {
     System.out.println("Null context: " + hashCode);
     return;
   }
   Logger.debug(context + " will notified");
   synchronized (context) {
     ((Context) context).pendingLock = success;
     context.notifyAll();
     Logger.debug(context + " notified");
   }
 }