Exemplo n.º 1
1
    @Override
    public void run() {
      boolean testComplete = true;
      int totalOps = 0, prevTotalOps = 0;
      do {
        testComplete = true;
        totalOps = 0;
        for (Thread thread : this.threads) {
          if (thread.getState() != Thread.State.TERMINATED) {
            testComplete = false;
          }
          totalOps += ((ClientThread) thread).getOpsDone();
        }

        if (totalOps != 0 && totalOps != prevTotalOps) {
          if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                "[status]\tThroughput(ops/sec): "
                    + Time.MS_PER_SECOND
                        * ((double) totalOps / (double) (System.currentTimeMillis() - startTime))
                    + "\tOperations: "
                    + totalOps);
          } else {
            System.currentTimeMillis();
          }
        }
        prevTotalOps = totalOps;
        try {
          sleep(intervalSec * Time.MS_PER_SECOND);
        } catch (InterruptedException e) {
        }
      } while (!testComplete);
    }
Exemplo n.º 2
0
  protected void connect(Socket socket) throws IOException {
    if (LOGGER.isInfoEnabled()) {
      SocketAddress address = socket.getRemoteSocketAddress();
      LOGGER.info().append("Connected to ").append(address).commit();
    }

    setSessionStatus(SessionStatus.SocketConnected);
    connect(getInputChannel(socket), getOutputChannel(socket));
  }
Exemplo n.º 3
0
 /** @see org.storevm.toolkits.session.zookeeper.handler.GetDataHandler#handle() */
 @SuppressWarnings("unchecked")
 @Override
 public <T> T handle() throws Exception {
   if (zookeeper != null) {
     String path = GROUP_NAME + NODE_SEP + id;
     // 检查指定的Session节点是否存在
     Stat stat = zookeeper.exists(path, false);
     // 如果节点存在则删除之
     if (stat != null) {
       // 查找数据节点是否存在,不存在就创建一个
       String dataPath = path + NODE_SEP + key;
       stat = zookeeper.exists(dataPath, false);
       if (stat == null) {
         // 创建数据节点
         zookeeper.create(dataPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         if (LOGGER.isInfoEnabled()) {
           LOGGER.info("创建数据节点完成[" + dataPath + "]");
         }
       }
       // 在节点上设置数据,所有数据必须可序列化
       if (data instanceof Serializable) {
         int dataNodeVer = -1;
         if (stat != null) {
           // 记录数据节点的版本
           dataNodeVer = stat.getVersion();
         }
         byte[] arrData = SerializationUtils.serialize(data);
         stat = zookeeper.setData(dataPath, arrData, dataNodeVer);
         if (LOGGER.isInfoEnabled()) {
           LOGGER.info("更新数据节点数据完成[" + dataPath + "][" + data + "]");
         }
         return (T) Boolean.TRUE;
       }
     }
   }
   return (T) Boolean.FALSE;
 }
 @Override
 public void onMessage(String key, String msg) {
   if (LOGGER.isInfoEnabled()) {
     LOGGER.info("redis event: " + key + " = " + msg);
   }
   if (msg.equals(Constants.REGISTER) || msg.equals(Constants.UNREGISTER)) {
     try {
       Jedis jedis = jedisPool.getResource();
       try {
         doNotify(jedis, key);
       } finally {
         jedis.close();
       }
     } catch (Throwable t) {
       LOGGER.error(t.getMessage(), t);
     }
   }
 }
 /**
  * 创建一个新的session
  *
  * @param request
  * @return
  */
 @Override
 public HttpSession newHttpSession(HttpServletRequest request) {
   // 类型检查
   if (!(request instanceof Request)) {
     LOGGER.warn("不是Jetty容器下的Request对象");
     return null;
   }
   // 将HttpServletRequest转换成Jetty容器的Request类型
   Request req = (Request) request;
   Session session =
       new JettyDistributedSession(
           (AbstractSessionManager) req.getSessionManager(), request, this);
   String id = session.getId();
   // 写cookie
   Cookie cookie =
       CookieHelper.writeSessionIdToCookie(
           id, req, req.getConnection().getResponse(), COOKIE_EXPIRY);
   if (cookie != null) {
     if (LOGGER.isInfoEnabled()) {
       LOGGER.info(
           "Wrote sid to Cookie,name:["
               + cookie.getName()
               + "],value:["
               + cookie.getValue()
               + "]");
     }
   }
   // 在ZooKeeper服务器上创建session节点,节点名称为Session ID
   // 创建元数据
   SessionMetaData metadata = new SessionMetaData();
   metadata.setId(id);
   long sessionTimeout =
       NumberUtils.toLong(config.getString(Configuration.SESSION_TIMEOUT)) * 60 * 1000;
   metadata.setMaxIdle(sessionTimeout); // 转换成毫秒
   try {
     client.execute(new CreateNodeHandler(id, metadata));
   } catch (Exception ex) {
     LOGGER.error("创建节点时发生异常,", ex);
   }
   addHttpSession(session);
   return session;
 }
Exemplo n.º 6
0
  /**
   * The Class Xliff2MSOfficeImpl.
   *
   * @author John Zhu
   * @version
   * @since JDK1.6
   */
  class Xliff2MSOfficeImpl {
    private boolean isInfoEnabled = LOGGER.isInfoEnabled();

    /**
     * Run.
     *
     * @param args the args
     * @param monitor the monitor
     * @return the map< string, string>
     * @throws ConverterException the converter exception
     */
    public Map<String, String> run(Map<String, String> args, IProgressMonitor monitor)
        throws ConverterException {
      monitor = Progress.getMonitor(monitor);
      ReverseConversionInfoLogRecord infoLogger =
          ConverterUtils.getReverseConversionInfoLogRecord();
      infoLogger.startConversion();
      Map<String, String> result = new HashMap<String, String>();
      String backfile = args.get(Converter.ATTR_TARGET_FILE);
      String middleBackfile = MSOffice2Xliff.getOutputFilePath(backfile);
      // 先转换成ODT,ODS,ODP等文件,然后在转换成DOC,XLS,PPT
      args.put(Converter.ATTR_TARGET_FILE, middleBackfile);
      try {
        // 把转换过程分为三部分共 10 个任,其中委派其它转换的操作占 4,检测 Open Office Service 是否可用占 2,调用 Open Office Service
        // 进行的操作占 4。
        monitor.beginTask(Messages.getString("msoffice2003.Xliff2MSOffice.task1"), 10);
        long startTime = 0;
        if (isInfoEnabled) {
          startTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger1"), startTime);
        }
        result = dependantConverter.convert(args, Progress.getSubMonitor(monitor, 4));
        long endTime = System.currentTimeMillis();
        if (isInfoEnabled) {
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger2"), endTime);
          LOGGER.info(
              Messages.getString("msoffice2003.Xliff2MSOffice.logger3"), endTime - startTime);
        }

        // 是否取消操作
        if (monitor.isCanceled()) {
          throw new OperationCanceledException(Messages.getString("msoffice2003.cancel"));
        }
        monitor.subTask(Messages.getString("msoffice2003.Xliff2MSOffice.task2"));
        if (isInfoEnabled) {
          startTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger4"), startTime);
        }
        File backup = new File(backfile);
        File middleFile = new File(middleBackfile);
        boolean openbyuser = DetectOORunning.isRunning(); // 判断是否手动启动
        boolean configration = false;
        Hashtable<String, String> ooParams = new Hashtable<String, String>();
        ooParams.put("ooPath", args.get("ooPath"));
        ooParams.put("port", args.get("ooPort"));
        StartupOO startupoo = new StartupOO(ooParams);
        configration = startupoo.detectConfOO();
        if (!configration) {
          ConverterUtils.throwConverterException(
              Activator.PLUGIN_ID, Messages.getString("msoffice2003.Xliff2MSOffice.msg1"));
        }
        if (isInfoEnabled) {
          endTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger5"), endTime);
          LOGGER.info(
              Messages.getString("msoffice2003.Xliff2MSOffice.logger6"), endTime - startTime);
        }
        monitor.worked(2);

        // 是否取消操作
        monitor.subTask(Messages.getString("msoffice2003.Xliff2MSOffice.task3"));
        if (isInfoEnabled) {
          startTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger7"), startTime);
        }
        MS2OOConverter ms2ooConverter = new MS2OOConverter(ooParams);
        try {
          ms2ooConverter.startconvert(middleFile, backup, openbyuser);
        } catch (Exception e) {
          if (Converter.DEBUG_MODE) {
            e.printStackTrace();
          }
          try {
            openbyuser = false;
            ms2ooConverter.startconvert(middleFile, backup, openbyuser);
          } catch (Exception e1) {
            if (Converter.DEBUG_MODE) {
              e1.printStackTrace();
            }
            if (!openbyuser) {
              CloseOOconnection.closeService(ms2ooConverter.getPort());
            }
            ConverterUtils.throwConverterException(
                Activator.PLUGIN_ID, Messages.getString("msoffice2003.Xliff2MSOffice.msg2"), e);
          }
        }
        middleFile.delete();
        if (isInfoEnabled) {
          endTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger8"), endTime);
          LOGGER.info(
              Messages.getString("msoffice2003.Xliff2MSOffice.logger9"), endTime - startTime);
        }
        monitor.worked(4);
      } catch (OperationCanceledException e) {
        throw e;
      } catch (ConverterException e) {
        throw e;
      } catch (Exception e) {
        ConverterUtils.throwConverterException(
            Activator.PLUGIN_ID, Messages.getString("msoffice2003.Xliff2MSOffice.msg2"), e);
      } finally {
        monitor.done();
      }
      result.put(Converter.ATTR_TARGET_FILE, backfile);
      infoLogger.endConversion();
      return result;
    }
  }
Exemplo n.º 7
0
  /**
   * Method to launch the action operations when a file system monitor event occurred.
   *
   * @param events The events queue.
   * @throws IOException
   */
  public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException {

    try {
      listenerForwarder.started();
      // ////////////////////////////////////////////////////////////////////
      //
      // Initializing input variables
      //
      // ////////////////////////////////////////////////////////////////////

      if (configuration == null) {
        throw new IllegalStateException("DataFlowConfig is null.");
      }

      // ////////////////////////////////////////////////////////////////////
      //
      // Initializing input variables
      //
      // ////////////////////////////////////////////////////////////////////

      // ////////////////////////////////////////////////////////////////////
      //
      // Checking input files.
      //
      // ////////////////////////////////////////////////////////////////////

      String ftpserverHost = configuration.getFtpserverHost();
      String ftpserverUSR = configuration.getFtpserverUSR();
      String ftpserverPWD = configuration.getFtpserverPWD();
      int ftpserverPort = configuration.getFtpserverPort();

      if ((ftpserverHost == null) || "".equals(ftpserverHost)) {
        throw new IllegalStateException("configuration.getFtpserverHost() is null.");
      }

      // //////////////////////////////////////////////
      // Retrive the added files from flow working dir
      // //////////////////////////////////////////////

      final List<File> filesToDelete = new ArrayList<File>();
      for (FileSystemEvent event : events) {
        final File input = event.getSource();
        if (input.exists() && input.isFile() && input.canRead()) {
          filesToDelete.add(input);

        } else {
          throw new IllegalStateException("No valid input file found for this data flow!");
        }
      }

      if (filesToDelete.size() <= 0) {
        throw new IllegalStateException("No valid file found for this data flow!");

        // /////////////////////////////////////////
        //
        // Deleting files from remote FTP Server
        //
        // /////////////////////////////////////////

      }
      if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Deleting file from FtpServer ... " + configuration.getFtpserverHost());
      }
      boolean ok = false;
      final FTPConnectMode connectMode =
          configuration
                  .getConnectMode()
                  .toString()
                  .equalsIgnoreCase(FTPConnectMode.ACTIVE.toString())
              ? FTPConnectMode.ACTIVE
              : FTPConnectMode.PASV;
      final int timeout = configuration.getTimeout();

      boolean zipOutput = configuration.isZipInput();
      String zipFileName = configuration.getZipFileName();

      String path = "path";

      if (zipOutput) {

        // ////////////////////////////////////////////////////////////////////
        // Build the real name of the remote zipped file before deleting
        // this
        // ////////////////////////////////////////////////////////////////////

        String remoteZipFile = zipFileName.concat(".zip");

        // /////////////////////////////////
        // Deleting the remote zipped file
        // /////////////////////////////////

        FTPHelperBare.deleteFileOrDirectory(
            ftpserverHost,
            remoteZipFile,
            false,
            path,
            ftpserverUSR,
            ftpserverPWD,
            ftpserverPort,
            connectMode,
            timeout);
      } else {

        // /////////////////////////////////////////////////////////////////////////
        // Scanning the files to delete array to distinguish files and
        // directories
        // /////////////////////////////////////////////////////////////////////////

        for (File file : filesToDelete) {
          if (file.isFile()) {
            FTPHelperBare.deleteFileOrDirectory(
                ftpserverHost,
                file.getName(),
                false,
                path,
                ftpserverUSR,
                ftpserverPWD,
                ftpserverPort,
                connectMode,
                timeout);

            // if(!ok)
            // break;
          } else {
            // sent = deleteDirectory("test", path);
            ok = deleteDirectory(file.getName(), path);

            if (!ok) {
              break;

            } else {
              // sent =
              // FTPHelper.deleteFileOrDirectory(configuration.getFtpserverHost(),
              // "test", true, path, ftpserverUSR, ftpserverPWD,
              // ftpserverPort, connectMode, timeout);
              FTPHelperBare.deleteFileOrDirectory(
                  ftpserverHost,
                  file.getName(),
                  true,
                  path,
                  ftpserverUSR,
                  ftpserverPWD,
                  ftpserverPort,
                  connectMode,
                  timeout);

              // if (!ok) {
              // break;
              // }
            }
          }
        }
      }

      // TODO: restruct previous calls so that if we are here, all went
      // well.
      // i.e. "ok" var should be useless

      if (ok) {
        if (LOGGER.isInfoEnabled()) {
          LOGGER.info("FTPDeleteAction: file SUCCESSFULLY deleted from FtpServer!");
        }
        listenerForwarder.completed();
      } else {
        if (LOGGER.isInfoEnabled()) {
          LOGGER.info(
              "FTPDeleteAction: file was NOT deleted from FtpServer due to connection errors!");
        }
        listenerForwarder.failed(null);
      }

      return events;

    } catch (Exception ex) {
      // if (LOGGER.isErrorEnabled())
      // LOGGER.error(t.getLocalizedMessage(), t); // not
      // logging rethrown exception
      listenerForwarder.failed(ex);
      throw new ActionException(this, ex.getMessage(), ex); // wrap
      // exception
    }
  }