Exemplo n.º 1
0
 /** Saves event into the list. */
 public synchronized void save() {
   myEvent.setNEID(myNE.getId());
   myEvent.setEnabled(true);
   myEvent.setDescription(desc.getText());
   int h = (Integer) hh.getValue();
   int m = (Integer) mm.getValue();
   double s = (Double) ss.getValue();
   myEvent.setTime(h + (m / 60.0) + (s / 3600.0));
   myEventManager.clearEvent(myEvent);
   myEventManager.addEvent(myEvent);
   if (eventTable != null) eventTable.updateData();
   return;
 }
Exemplo n.º 2
0
 public AbstractEvent nextEvent() {
   AbstractEvent pr = null;
   if (T.stopRequest()) return null;
   if (T.currentTimePoint % 60 == 0) {
     int x = R.nextInt() % probPeople;
     // x = 0;
     if (x == 0) {
       r_id++;
       int pickupLocation = map.V.get(R.nextInt(map.V.size()));
       int deliveryLocation = map.V.get(R.nextInt(map.V.size()));
       pr = new PeopleRequest(pickupLocation, deliveryLocation);
       pr.id = r_id;
       log.println(
           "EventGenerator::nextEvent --> At "
               + T.currentTimePointHMS()
               + "["
               + T.currentTimePoint
               + "]"
               + " --> people request from "
               + pickupLocation
               + " to "
               + deliveryLocation
               + " arrive");
       return pr;
     }
     // }
     // if(T.currentTimePoint%60 == 0){
     x = R.nextInt() % probParcel;
     if (x == 0) {
       r_id++;
       int pickupLocation = map.V.get(R.nextInt(map.V.size()));
       int deliveryLocation = map.V.get(R.nextInt(map.V.size()));
       pr = new ParcelRequest(pickupLocation, deliveryLocation);
       pr.id = r_id;
       log.println(
           "EventGenerator::nextEvent --> At "
               + T.currentTimePointHMS()
               + "["
               + T.currentTimePoint
               + "]"
               + " --> parcel request from "
               + pickupLocation
               + " to "
               + deliveryLocation
               + " arrive");
       return pr;
     }
   }
   return pr;
 }
Exemplo n.º 3
0
 /**
  * Initializes event editing panel.
  *
  * @param ne Network Element.
  * @param em Event Manager.
  * @param evt Event.
  */
 protected void initialize(AbstractNetworkElement ne, EventManager em) {
   myNE = ne;
   myEventManager = em;
   setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
   JPanel pH = new JPanel(new FlowLayout());
   JLabel lD =
       new JLabel(
           "<html><font color=\"blue\">"
               + TypesHWC.typeString(myNE.getType())
               + " "
               + myNE.toString()
               + "</font></html>");
   pH.add(lD);
   add(pH);
   // Box dp = Box.createVerticalBox();
   JPanel pD = new JPanel(new BorderLayout());
   pD.setBorder(BorderFactory.createTitledBorder("Description"));
   desc.setText(myEvent.getDescription());
   pD.add(new JScrollPane(desc), BorderLayout.CENTER);
   // dp.add(pD);
   add(pD);
   fillPanel();
   // Box fp = Box.createVerticalBox();
   JPanel pT = new JPanel(new FlowLayout());
   pT.setBorder(BorderFactory.createTitledBorder("Activation Time"));
   hh = new JSpinner(new SpinnerNumberModel(Util.getHours(myEvent.getTime()), 0, 99, 1));
   hh.setEditor(new JSpinner.NumberEditor(hh, "00"));
   pT.add(hh);
   pT.add(new JLabel("h "));
   mm = new JSpinner(new SpinnerNumberModel(Util.getMinutes(myEvent.getTime()), 0, 59, 1));
   mm.setEditor(new JSpinner.NumberEditor(mm, "00"));
   pT.add(mm);
   pT.add(new JLabel("m "));
   ss = new JSpinner(new SpinnerNumberModel(Util.getSeconds(myEvent.getTime()), 0, 59.99, 1));
   ss.setEditor(new JSpinner.NumberEditor(ss, "00.##"));
   pT.add(ss);
   pT.add(new JLabel("s"));
   // fp.add(pT);
   add(pT);
   winEE = new WindowEventEditor(this, null);
   winEE.setVisible(true);
   return;
 }
  /** {@inheritDoc} */
  @Override
  public void read(final DataInput in) throws IOException {

    super.read(in);

    this.jobVertexID.read(in);
    this.jobVertexName = StringRecord.readString(in);
    this.totalNumberOfSubtasks = in.readInt();
    this.indexOfSubtask = in.readInt();
    this.currentExecutionState = EnumUtils.readEnum(in, ExecutionState.class);
    this.description = StringRecord.readString(in);
  }
  /** {@inheritDoc} */
  @Override
  public void write(final DataOutput out) throws IOException {

    super.write(out);

    this.jobVertexID.write(out);
    StringRecord.writeString(out, this.jobVertexName);
    out.writeInt(this.totalNumberOfSubtasks);
    out.writeInt(this.indexOfSubtask);
    EnumUtils.writeEnum(out, this.currentExecutionState);
    StringRecord.writeString(out, this.description);
  }
  /**
   * Fires the given event.
   *
   * @param event The event to fire.
   */
  private void internalFire(final AbstractEvent event) {
    assert event != null : "Event cannot be null!";

    final EventContext<AbstractEvent> context = new EventContext<AbstractEvent>(event);
    for (final EventHandler handler : event.getHandlers()) {
      if (!handler.isEnabled()) {
        // If the event handler is disabled, skip the execution.
        continue;
      }

      try {
        handler.getListenerMethod().invoke(handler.getListenerObject(), context);
      } catch (final IllegalArgumentException ex) {
        SimpleEventManager.LOGGER.error(
            "It seems that the event listener method \""
                + handler.getListenerMethod().getName()
                + "\" in class \""
                + handler.getListenerMethod().getDeclaringClass().getName()
                + "\" defines wrong arguments. The one and only argument should be a \""
                + EventContext.class.getName()
                + "\"!",
            ex);
      } catch (final IllegalAccessException ex) {
        SimpleEventManager.LOGGER.error(
            "An error occurred whilst firing event \""
                + event
                + "\" for method \""
                + handler.getListenerMethod().getName()
                + "\" in class \""
                + handler.getListenerMethod().getDeclaringClass().getName()
                + "\"!",
            ex);
      } catch (final InvocationTargetException ex) {
        SimpleEventManager.LOGGER.error(
            "An error occurred whilst firing event \""
                + event
                + "\" for method \""
                + handler.getListenerMethod().getName()
                + "\" in class \""
                + handler.getListenerMethod().getDeclaringClass().getName()
                + "\"!",
            ex);
      }
    }
  }
  /**
   * Sends message to RabbitMQ
   *
   * @param event The message
   */
  public void send(AbstractEvent event) {

    send(event, event.getEventId());
  }