static {
    if (!Boolean.getBoolean(GridSystemProperties.GG_JETTY_LOG_NO_OVERRIDE)) {
      String ctgrJetty = "org.eclipse.jetty"; // WARN for this category.
      String ctgrJettyUtil = "org.eclipse.jetty.util.log"; // ERROR for this...
      String ctgrJettyUtilComp = "org.eclipse.jetty.util.component"; // ...and this.

      try {
        Class<?> logCls = Class.forName("org.apache.log4j.Logger");

        Object logJetty = logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJetty);
        Object logJettyUtil =
            logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJettyUtil);
        Object logJettyUtilComp =
            logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJettyUtilComp);

        Class<?> lvlCls = Class.forName("org.apache.log4j.Level");

        Object warnLvl = lvlCls.getField("WARN").get(null);
        Object errLvl = lvlCls.getField("ERROR").get(null);

        logJetty.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, warnLvl);
        logJettyUtil.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, errLvl);
        logJettyUtilComp.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, errLvl);
      } catch (Exception ignored) {
        // No-op.
      }
    }
  }
  /**
   * @param cacheName Cache name.
   * @param key Key.
   * @return Data key.
   * @throws Exception In case of error.
   */
  private Object key(String cacheName, int key) throws Exception {
    Class<?> cls = Class.forName(GridSpringDynamicCacheManager.class.getName() + "$DataKey");

    Constructor<?> cons = cls.getDeclaredConstructor(String.class, Object.class);

    cons.setAccessible(true);

    return cons.newInstance(cacheName, key);
  }
  /** {@inheritDoc} */
  @Override
  public void start() throws GridException {
    if (ctx.isEnterprise()) {
      Package pkg = getClass().getPackage();

      if (pkg == null)
        throw new GridException(
            "Internal error (package object was not found) for: " + getClass().getName());

      if (ctx.isEnterprise()) {
        try {
          Class<?> cls = Class.forName(pkg.getName() + ".GridEnterpriseSecureSessionHandler");

          sesHnd =
              (GridSecureSessionHandler)
                  cls.getConstructor(GridSecureSessionSpi[].class)
                      .newInstance(new Object[] {getProxies()});
        } catch (ClassNotFoundException e) {
          throw new GridException(
              "Failed to create enterprise secure session handler (implementing class "
                  + "was not found)",
              e);
        } catch (InvocationTargetException e) {
          throw new GridException(
              "Failed to create enterprise secure session handler (target constructor "
                  + "has thrown an exception",
              e.getCause());
        } catch (InstantiationException e) {
          throw new GridException(
              "Failed to create enterprise secure session handler (object cannot be "
                  + "instantiated)",
              e);
        } catch (NoSuchMethodException e) {
          throw new GridException(
              "Failed to create enterprise secure session handler (target constructor "
                  + "could not be found)",
              e);
        } catch (IllegalAccessException e) {
          throw new GridException(
              "Failed to create enterprise secure session handler (object access is not"
                  + " allowed)",
              e);
        }
      }
    } else sesHnd = new GridCommunitySecureSessionHandler();

    startSpi();

    if (log.isDebugEnabled()) log.debug(startInfo());
  }
Esempio n. 4
0
  /**
   * Creates JUnit test router. Note that router must have a no-arg constructor.
   *
   * @return JUnit router instance.
   */
  @SuppressWarnings({"unchecked"})
  private GridTestRouter createRouter() {
    try {
      if (routerCls == null) {
        routerCls = (Class<? extends GridTestRouter>) Class.forName(routerClsName);
      } else {
        routerClsName = routerCls.getName();
      }

      return routerCls.newInstance();
    } catch (ClassNotFoundException e) {
      throw new GridRuntimeException("Failed to initialize JUnit router: " + routerClsName, e);
    } catch (IllegalAccessException e) {
      throw new GridRuntimeException("Failed to initialize JUnit router: " + routerClsName, e);
    } catch (InstantiationException e) {
      throw new GridRuntimeException("Failed to initialize JUnit router: " + routerClsName, e);
    }
  }
Esempio n. 5
0
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    id = in.readInt();

    String clsName = in.readUTF();

    if (clsName == null) innerSplit = in.readObject();
    else {
      // Split wrapper only used when classes available in our classpath, so Class.forName is ok
      // here.
      Class<Writable> cls = (Class<Writable>) Class.forName(clsName);

      try {
        innerSplit = U.newInstance(cls);
      } catch (GridException e) {
        throw new IOException(e);
      }

      ((Writable) innerSplit).readFields(in);
    }
  }
Esempio n. 6
0
  /**
   * Runs JDBC example.
   *
   * @param args Command line arguments.
   * @throws Exception In case of error.
   */
  public static void main(String[] args) throws Exception {
    Grid grid = G.start("examples/config/spring-cache.xml");

    Connection conn = null;

    try {
      // Populate cache with data.
      populate(grid.cache(CACHE_NAME));

      // Register JDBC driver.
      Class.forName("org.gridgain.jdbc.GridJdbcDriver");

      // Open JDBC connection.
      conn =
          DriverManager.getConnection("jdbc:gridgain://localhost/" + CACHE_NAME, configuration());

      X.println(">>>");

      // Query all persons.
      queryAllPersons(conn);

      X.println(">>>");

      // Query person older than 30 years.
      queryPersons(conn, 30);

      X.println(">>>");

      // Query persons working in GridGain.
      queryPersonsInOrganization(conn, "GridGain");

      X.println(">>>");
    } finally {
      // Close JDBC connection.
      if (conn != null) conn.close();

      G.stop(true);
    }
  }