/** * Creates configuration properties object for new connection. * * <p>See GridGain client javadoc for more information: {@link GridClientConfiguration}. * * <p>All parameters are optional. * * @return Configuration. */ private static Properties configuration() { Properties cfg = new Properties(); // Node ID where to execute query. This property is useful when you have several // local caches with same name in topology and want to specify which of them to connect. // // Uncomment line below and provide correct ID if needed. // cfg.setProperty(CONF_NODE_ID, "E0869485-512C-41F9-866D-BE906B591BEA"); // Communication protocol (TCP or HTTP). Default is TCP. cfg.setProperty(CONF_PROTO, "TCP"); // Socket timeout. Default is 0 which means infinite timeout. cfg.setProperty(CONF_TIMEOUT, "0"); // Flag indicating whether TCP_NODELAY flag should be enabled for outgoing // connections. Default is true. cfg.setProperty(CONF_TCP_NO_DELAY, "true"); // Flag indicating that SSL is needed for connection. Default is false. cfg.setProperty(CONF_SSL_ENABLED, "false"); // SSL context factory class name. Class must extend // org.gridgain.client.ssl.GridSslContextFactory // interface, have default constructor and be available on classpath. // Ignored if SSL is disabled. cfg.setProperty(CONF_SSL_FACTORY, "org.gridgain.client.ssl.GridSslBasicContextFactory"); // SSL pass-phrase. // Ignored is SSL is disabled. cfg.setProperty(CONF_CREDS, "s3cr3t"); // Flag indicating that topology is cached internally. Cache will be refreshed // in the background with interval defined by CONF_TOP_REFRESH_FREQ property // (see below). Default is false. cfg.setProperty(CONF_TOP_CACHE_ENABLED, "false"); // Topology cache refresh frequency. Default is 2000 ms. cfg.setProperty(CONF_TOP_REFRESH_FREQ, "2000"); // Maximum amount of time that connection can be idle before it is closed. // Default is 30000 ms. cfg.setProperty(CONF_MAX_IDLE_TIME, "30000"); return cfg; }
/** * Starts Grid instance. Note that if grid is already started, then it will be looked up and * returned from this method. * * @return Started grid. */ private Grid startGrid() { Properties props = System.getProperties(); gridName = props.getProperty(GRIDGAIN_NAME.name()); if (!props.containsKey(GRIDGAIN_NAME.name()) || G.state(gridName) != GridFactoryState.STARTED) { selfStarted = true; // Set class loader for the spring. ClassLoader curCl = Thread.currentThread().getContextClassLoader(); // Add no-op logger to remove no-appender warning. Appender app = new NullAppender(); Logger.getRootLogger().addAppender(app); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Grid grid = G.start(cfgPath); gridName = grid.name(); System.setProperty(GRIDGAIN_NAME.name(), grid.name()); return grid; } catch (GridException e) { throw new GridRuntimeException("Failed to start grid: " + cfgPath, e); } finally { Logger.getRootLogger().removeAppender(app); Thread.currentThread().setContextClassLoader(curCl); } } return G.grid(gridName); }
/** * Initializes store. * * @throws GridException If failed to initialize. */ private void init() throws GridException { if (initGuard.compareAndSet(false, true)) { if (log.isDebugEnabled()) log.debug("Initializing cache store."); try { if (sesFactory != null) // Session factory has been provided - nothing to do. return; if (!F.isEmpty(hibernateCfgPath)) { try { URL url = new URL(hibernateCfgPath); sesFactory = new Configuration().configure(url).buildSessionFactory(); if (log.isDebugEnabled()) log.debug("Configured session factory using URL: " + url); // Session factory has been successfully initialized. return; } catch (MalformedURLException e) { if (log.isDebugEnabled()) log.debug("Caught malformed URL exception: " + e.getMessage()); } // Provided path is not a valid URL. File? File cfgFile = new File(hibernateCfgPath); if (cfgFile.exists()) { sesFactory = new Configuration().configure(cfgFile).buildSessionFactory(); if (log.isDebugEnabled()) log.debug("Configured session factory using file: " + hibernateCfgPath); // Session factory has been successfully initialized. return; } // Provided path is not a file. Classpath resource? sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory(); if (log.isDebugEnabled()) log.debug("Configured session factory using classpath resource: " + hibernateCfgPath); } else { if (hibernateProps == null) { U.warn( log, "No Hibernate configuration has been provided for store (will use default)."); hibernateProps = new Properties(); hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL); hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL); hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO); } Configuration cfg = new Configuration(); cfg.setProperties(hibernateProps); assert resourceAvailable(MAPPING_RESOURCE); cfg.addResource(MAPPING_RESOURCE); sesFactory = cfg.buildSessionFactory(); if (log.isDebugEnabled()) log.debug("Configured session factory using properties: " + hibernateProps); } } catch (HibernateException e) { throw new GridException("Failed to initialize store.", e); } finally { initLatch.countDown(); } } else if (initLatch.getCount() > 0) U.await(initLatch); if (sesFactory == null) throw new GridException("Cache store was not properly initialized."); }
/** * Loads test configuration. * * @throws Exception if configuration is unawailable or broken. */ private void loadTestConfiguration() throws Exception { assert TEST_CONFIGURATION_FILE.isFile(); InputStream in = null; Properties p = new Properties(); try { in = new FileInputStream(TEST_CONFIGURATION_FILE); p.load(in); } finally { U.closeQuiet(in); } clientNodes = Integer.parseInt(p.getProperty("client.nodes.count")); srvNodes = Integer.parseInt(p.getProperty("server.nodes.count")); threadsPerClient = Integer.parseInt(p.getProperty("threads.per.client")); cancelRate = Integer.parseInt(p.getProperty("cancel.rate")); submitDelay = Long.parseLong(p.getProperty("submit.delay")); taskParams = new GridJobLoadTestParams( Integer.parseInt(p.getProperty("jobs.count")), Integer.parseInt(p.getProperty("jobs.test.duration")), Integer.parseInt(p.getProperty("jobs.test.completion.delay")), Double.parseDouble(p.getProperty("jobs.failure.probability"))); }