Example #1
0
 public void initAgents(ArrayList machineAgentArray) {
   fUGeneralStrategy = new UBaseAgent("su", "supasswd", "Super User", 0);
   fServer.appendStrategy(fUGeneralStrategy);
   fCProtocol = fUGeneralStrategy.getUmcp();
   fCommandHashMap = fCProtocol.getCommandHashMap();
   Iterator iter = machineAgentArray.iterator();
   while (iter.hasNext()) {
     fServer.appendStrategy((UBaseAgent) iter.next());
   }
 }
Example #2
0
 public void actionPerformed(ActionEvent e) {
   UServerStatus status = fServer.nextStatus();
   switch (status.getState()) {
     case UServerStatus.AFTER_SETTLEMENT:
       fUpdateTimer.stop();
       break;
     case UServerStatus.ACCEPT_ORDERS:
       fServer.recieveOrdersFromLocalAgents();
       break;
   }
   fGui.gUpdate();
 }
Example #3
0
 /** @see cmdCore.ICommand#doIt() */
 public UCommandStatus doIt() {
   try {
     fSpotArray.clear();
     fStatus = fUMart.doSpotPrice(fSpotArray, fBrandName, fNoOfSteps);
     if (fStatus.getStatus()) {
       fAgent.sendMessage("+ACCEPT");
       Iterator itr = fSpotArray.iterator();
       while (itr.hasNext()) {
         HashMap hm = (HashMap) itr.next();
         String result = "";
         result += hm.get(STRING_BRAND_NAME).toString();
         result += " " + hm.get(INT_DAY).toString();
         result += ":" + hm.get(INT_BOARD_NO).toString();
         result += ":" + hm.get(INT_STEP).toString();
         result += " " + hm.get(LONG_PRICE).toString();
         fAgent.sendMessage(result);
       }
     } else {
       fAgent.sendMessage("+ERROR " + fStatus.getErrorCode());
       fAgent.sendMessage(fStatus.getErrorMessage());
     }
   } catch (Exception e) {
     fAgent.sendMessage("+ERROR " + ICommand.INVALID_ARGUMENTS);
     fAgent.sendMessage("USAGE: ORDERCANCEL <ORDERID>");
   }
   fAgent.flushMessage();
   return fStatus;
 }
Example #4
0
 /** @see cmdCore.ICommand#doIt() */
 public UCommandStatus doIt() {
   try {
     fServerTimeInfo.clear();
     fStatus = fUMart.doServerTime(fServerTimeInfo);
     if (fStatus.getStatus()) {
       fAgent.sendMessage("+ACCEPT");
       fAgent.sendMessage(fServerTimeInfo.get(STRING_SERVER_TIME).toString());
     } else {
       fAgent.sendMessage("+ERROR " + fStatus.getErrorCode());
       fAgent.sendMessage(fStatus.getErrorMessage());
     }
   } catch (Exception e) {
     System.err.println("Error in UCServerTime.doIt");
     System.exit(5);
   }
   fAgent.flushMessage();
   return fStatus;
 }
Example #5
0
 public UServerManager() {
   try {
     ULogoWindow logow = new ULogoWindow();
     logow.setVisible(true);
     Thread.sleep(2500);
     logow.dispose();
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   fParam.setConnectionType(UParameters.CONNECTION_TYPE_NETWORK);
   fParamDialog = new UServerManagerParamDialog();
   fParamDialog.setLocationRelativeTo((Frame) null);
   fParamDialog.setVisible(true);
   if (!fParamDialog.getStatus()) {
     System.exit(0);
     // 以下の部分はサーバの初期化による出力を拾えないための方策.
     // 非常にまずいが仕方ない.標準出力タブは必ず入れる.
   }
   System.setOut(UParameters.fPrintStream);
   fUpdateTimer = new javax.swing.Timer(fInterval * 1000, this);
   fUpdateTimer.setInitialDelay(0);
   fServer =
       new UMartNetwork(
           fParam.getMemberLog(),
           fParam.getPriceInfoDB(),
           fParam.getStartPoint(),
           fParam.getSeed(),
           fParam.getDays(),
           fParam.getBoardPerDay(),
           fParamNet.getPort());
   if (fParam.isLogCreate()) {
     try {
       fServer.initLog();
     } catch (IOException ioex) {
       JOptionPane.showMessageDialog(
           null,
           fRb.getString("ERROR_CANNOT_CREATE_LOGS"),
           fRb.getString("ERROR_DIALOG_TITLE"),
           JOptionPane.ERROR_MESSAGE);
       System.exit(5);
     } catch (Exception ex) {
       StringWriter sw = new StringWriter();
       PrintWriter pw = new PrintWriter(sw);
       ex.printStackTrace(pw);
       JOptionPane.showMessageDialog(
           null,
           fRb.getString("ERROR_FATAL") + "\n" + sw.toString(),
           fRb.getString("ERROR_DIALOG_TITLE"),
           JOptionPane.ERROR_MESSAGE);
       System.exit(5);
     }
   }
   fServer.startLoginManager();
   initAgents(fParam.getMachineAgentArray());
   fGui = new UServerManagerMainWindow(this, fParam.getTabs());
   fParam.setMainComponet(fGui);
   fGui.setTimer(fUpdateTimer);
   fGui.mainImpl();
   ActionListener guiUpdater =
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           fGui.gUpdate();
         }
       };
   fGuiUpdateTimer = new javax.swing.Timer(TIMER_INTERVAL * 1000, guiUpdater);
   fGuiUpdateTimer.start();
   // 1日目の1回目の注文期間に進めておく
   fUpdateTimer.setRepeats(false);
   fUpdateTimer.start();
 }