com.github.rinde.rinsim.event.Event类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中com.github.rinde.rinsim.event.Event类的一些代码示例,展示了Event类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Event类的具体详情如下:
包路径:com.github.rinde.rinsim.event.Event
类名称:Event

Event介绍

[英]The base event class. It is immutable.
[中]基本事件类。它是不变的。

代码示例

代码示例来源:origin: com.github.rinde/rinsim-event

public void safeDispatchEvent(Event e) {
 dispatching.incrementAndGet();
 final Set<Listener> targetListeners;
 synchronized (listeners) {
  checkCanDispatchEventType(e.getEventType());
  targetListeners = ImmutableSet.copyOf(listeners.get(e.getEventType()));
 }
 for (final Listener l : targetListeners) {
  l.handleEvent(e);
 }
 dispatching.decrementAndGet();
 update();
}

代码示例来源:origin: com.github.rinde/rinlog

/**
 * Notifies this blackboard user of a change in the environment.
 */
public void update() {
 eventDispatcher
  .dispatchEvent(new Event(CommunicatorEventType.CHANGE, this));
}

代码示例来源:origin: rinde/RinSim

void doHandleEvent(Event e) {
 synchronized (computingSimSolvers) {
  final boolean isComputingBefore = isComputing();
  LOGGER.trace("receive: {}, computing: {}, clock is ticking: {}, {}", e,
   isComputingBefore, clock.isTicking(), computingSimSolvers);
  if (e.getEventType() == EventType.START_COMPUTING) {
   if (!isComputingBefore) {
    LOGGER.debug("start computing -> switch to real time");
    clock.switchToRealTime();
   }
   computingSimSolvers.add((RtSimSolverSchedulerBridge) e.getIssuer());
  } else if (e.getEventType() == EventType.DONE_COMPUTING) {
   // done computing
   checkState(computingSimSolvers.remove(e.getIssuer()));
   // if (!isComputing()) {
   // stop();
   // }
  } else {
   throw new IllegalArgumentException("Unexpected event: " + e);
  }
 }
}

代码示例来源:origin: rinde/RinSim

@Override
 public void handleEvent(Event event) {
  assertSame(event.toString(), modelRef, event.getIssuer());
 }
}, PDPModelEventType.values());

代码示例来源:origin: com.github.rinde/rinsim-pdptw

@Override
public void handleEvent(Event e) {
 if (e.getEventType() == ClockEventType.STARTED) {
  startTimeReal = System.currentTimeMillis();
  startTimeSim = clock.getCurrentTime();
  computationTime = 0;
 } else if (e.getEventType() == ClockEventType.STOPPED) {
  computationTime = System.currentTimeMillis() - startTimeReal;
  simulationTime = clock.getCurrentTime() - startTimeSim;
 } else if (e.getEventType() == RoadEventType.MOVE) {
  verify(e instanceof MoveEvent);
  final MoveEvent me = (MoveEvent) e;
     clock.getCurrentTime());
    if (totalVehicles == lastArrivalTimeAtDepot.size()) {
     eventDispatcher.dispatchEvent(new Event(
      StatsProvider.EventTypes.ALL_VEHICLES_AT_DEPOT, this));
 } else if (e.getEventType() == PDPModelEventType.START_PICKUP) {
  verify(e instanceof PDPModelEvent);
  final PDPModelEvent pme = (PDPModelEvent) e;
 } else if (e.getEventType() == PDPModelEventType.END_PICKUP) {
  totalPickups++;
 } else if (e.getEventType() == PDPModelEventType.START_DELIVERY) {
  final PDPModelEvent pme = (PDPModelEvent) e;
 } else if (e.getEventType() == PDPModelEventType.END_DELIVERY) {
  totalDeliveries++;

代码示例来源:origin: rinde/RinSim

@Override
public void handleEvent(Event e) {
 history.add(e);
 e.toString();
}

代码示例来源:origin: rinde/RinSim

@Override
public void handleEvent(Event e) {
 if (e.getEventType() == ClockEventType.STARTED) {
  startTimeReal = System.currentTimeMillis();
  startTimeSim = clock.getCurrentTime();
  computationTime = 0;
 } else if (e.getEventType() == ClockEventType.STOPPED) {
  computationTime = System.currentTimeMillis() - startTimeReal;
  simulationTime = clock.getCurrentTime() - startTimeSim;
 } else if (e.getEventType() == RoadEventType.MOVE) {
  verify(e instanceof MoveEvent);
  final MoveEvent me = (MoveEvent) e;
     clock.getCurrentTime());
    if (totalVehicles == lastArrivalTimeAtDepot.size()) {
     eventDispatcher.dispatchEvent(new Event(
      StatsProvider.EventTypes.ALL_VEHICLES_AT_DEPOT, this));
 } else if (e.getEventType() == PDPModelEventType.START_PICKUP) {
  verify(e instanceof PDPModelEvent);
  final PDPModelEvent pme = (PDPModelEvent) e;
 } else if (e.getEventType() == PDPModelEventType.END_PICKUP) {
  totalPickups++;
 } else if (e.getEventType() == PDPModelEventType.START_DELIVERY) {
  final PDPModelEvent pme = (PDPModelEvent) e;
 } else if (e.getEventType() == PDPModelEventType.END_DELIVERY) {
  totalDeliveries++;

代码示例来源:origin: rinde/RinSim

public void safeDispatchEvent(Event e) {
 dispatching.incrementAndGet();
 final Set<Listener> targetListeners;
 synchronized (listeners) {
  checkCanDispatchEventType(e.getEventType());
  targetListeners = ImmutableSet.copyOf(listeners.get(e.getEventType()));
 }
 for (final Listener l : targetListeners) {
  l.handleEvent(e);
 }
 dispatching.decrementAndGet();
 update();
}

代码示例来源:origin: com.github.rinde/rinlog

@Override
public void receiveParcel(Auctioneer<T> auctioneer, Parcel p,
  long auctionStartTime) {
 LOGGER.info("{} receiveParcel {}", this, p);
 assignedParcels.add(p);
 eventDispatcher
  .dispatchEvent(new Event(CommunicatorEventType.CHANGE, this));
}

代码示例来源:origin: rinde/RinSim

@Test
public void followPathEventIssuerType() {
 final MovingRoadUser user = new TestRoadUser();
 model.addObjectAt(user, SW);
 final ListenerEventHistory list = new ListenerEventHistory();
 model.getEventAPI().addListener(list, RoadEventType.MOVE);
 assertTrue(list.getHistory().isEmpty());
 model.followPath(user, newLinkedList(asList(SW, SE, NE, NW)),
  TimeLapseFactory.create(0, 10));
 assertEquals(1, list.getHistory().size());
 assertEquals(RoadEventType.MOVE, list.getHistory().get(0).getEventType());
 assertEquals(model, list.getHistory().get(0).getIssuer());
}

代码示例来源:origin: com.github.rinde/rinsim-event

/**
 * Dispatch an event. Notifies all listeners that are listening for this type
 * of event.
 * @param e The event to be dispatched, only events with a supported type can
 *          be dispatched.
 */
public void dispatchEvent(Event e) {
 synchronized (listeners) {
  dispatching.incrementAndGet();
  checkCanDispatchEventType(e.getEventType());
  for (final Listener l : listeners.get(e.getEventType())) {
   l.handleEvent(e);
  }
  dispatching.decrementAndGet();
 }
 update();
}

代码示例来源:origin: com.github.rinde/rinlog

protected void dispatchChangeEvent() {
 eventDispatcher.dispatchEvent(
  new Event(RoutePlannerEventType.CHANGE, this));
}

代码示例来源:origin: rinde/RinSim

@Test
public void moveToEventIssuerType() {
 final MovingRoadUser user = new TestRoadUser();
 model.addObjectAt(user, SW);
 final ListenerEventHistory list = new ListenerEventHistory();
 model.getEventAPI().addListener(list, RoadEventType.MOVE);
 assertTrue(list.getHistory().isEmpty());
 model.moveTo(user, NW, TimeLapseFactory.create(0, 10));
 assertEquals(1, list.getHistory().size());
 assertEquals(RoadEventType.MOVE, list.getHistory().get(0).getEventType());
 assertEquals(model, list.getHistory().get(0).getIssuer());
}

代码示例来源:origin: rinde/RinSim

/**
 * Dispatch an event. Notifies all listeners that are listening for this type
 * of event.
 * @param e The event to be dispatched, only events with a supported type can
 *          be dispatched.
 */
public void dispatchEvent(Event e) {
 synchronized (listeners) {
  dispatching.incrementAndGet();
  checkCanDispatchEventType(e.getEventType());
  for (final Listener l : listeners.get(e.getEventType())) {
   l.handleEvent(e);
  }
  dispatching.decrementAndGet();
 }
 update();
}

代码示例来源:origin: rinde/RinSim

/**
 * Start the simulation.
 */
@Override
public final void start() {
 checkState(!isTicking(), "Time is already ticking.");
 isTicking = true;
 eventDispatcher.dispatchEvent(new Event(ClockEventType.STARTED, this));
 doStart();
 eventDispatcher.dispatchEvent(new Event(ClockEventType.STOPPED, this));
}

代码示例来源:origin: rinde/RinSim

@Override
 public void handleEvent(Event e) {
  if (e
   .getEventType() == ScenarioController.EventType.SCENARIO_FINISHED) {
   sim.stop();
  }
 }
});

代码示例来源:origin: com.github.rinde/rinlog

@Override
public boolean releaseParcel(Parcel p) {
 checkArgument(!pdpModel.get().getParcelState(p).isPickedUp()
  && !pdpModel.get().getParcelState(p).isTransitionState());
 LOGGER.info("{} releaseParcel {}", this, p);
 checkArgument(assignedParcels.contains(p));
 assignedParcels.remove(p);
 checkState(!assignedParcels.contains(p));
 eventDispatcher
  .dispatchEvent(new Event(CommunicatorEventType.CHANGE, this));
 return true;
}

代码示例来源:origin: com.github.rinde/rinsim-example

@Override
public void handleEvent(Event e) {
 verify(e instanceof PDPModelEvent);
 final PDPModelEvent event = (PDPModelEvent) e;
 final Box box = (Box) verifyNotNull(event.parcel);
 if (e.getEventType() == PDPModelEventType.END_PICKUP) {
  occupiedPositions.remove(box.getPickupLocation());
 }
 if (e.getEventType() == PDPModelEventType.END_DELIVERY) {
  final long duration = DoubleMath.roundToLong(
   FactoryExample.SERVICE_DURATION / 2d
    + rng.nextDouble() * FactoryExample.SERVICE_DURATION,
   RoundingMode.CEILING);
  simulator.get().unregister(box);
  final BoxHandle bh = box.boxHandle;
  bh.wordIndex = (bh.wordIndex + 1) % points.size();
  final Point dest;
  if (bh.index >= points.get(bh.wordIndex).size()) {
   dest = rndBorder();
  } else {
   dest = points.get(bh.wordIndex).get(bh.index);
   occupiedPositions.add(dest);
  }
  final Box newBox = new Box(box.getDeliveryLocation(),
   dest, duration, bh);
  bh.box = newBox;
  simulator.get().register(newBox);
 }
}

代码示例来源:origin: rinde/RinSim

void close() {
 if (!shell.isDisposed()) {
  display.asyncExec(new Runnable() {
   @Override
   public void run() {
    shell.close();
   }
  });
 }
 if (builder.callback().isPresent()) {
  builder.callback().get()
   .handleEvent(new Event(Clock.ClockEventType.STOPPED, null));
 }
}

代码示例来源:origin: rinde/RinSim

@Override
public void handleEvent(Event e) {
 verify(e instanceof PDPModelEvent);
 final PDPModelEvent event = (PDPModelEvent) e;
 final Box box = (Box) verifyNotNull(event.parcel);
 if (e.getEventType() == PDPModelEventType.END_PICKUP) {
  occupiedPositions.remove(box.getPickupLocation());
 }
 if (e.getEventType() == PDPModelEventType.END_DELIVERY) {
  final long duration = DoubleMath.roundToLong(
   FactoryExample.SERVICE_DURATION / 2d
    + rng.nextDouble() * FactoryExample.SERVICE_DURATION,
   RoundingMode.CEILING);
  simulator.get().unregister(box);
  final BoxHandle bh = box.boxHandle;
  bh.wordIndex = (bh.wordIndex + 1) % points.size();
  final Point dest;
  if (bh.index >= points.get(bh.wordIndex).size()) {
   dest = rndBorder();
  } else {
   dest = points.get(bh.wordIndex).get(bh.index);
   occupiedPositions.add(dest);
  }
  final Box newBox = new Box(box.getDeliveryLocation(),
   dest, duration, bh);
  bh.box = newBox;
  simulator.get().register(newBox);
 }
}

相关文章