Package krati.util

Examples of krati.util.Chronos


  public synchronized boolean roll(Collection<E> elements) {
    if(elements == null || elements.size() == 0) {
      return false;
    }
   
    Chronos c = new Chronos();
    HashMap<String, List<E>> map = new HashMap<String, List<E>>();
   
    try {
      long maxScn = collect(map, elements);
      store(map, maxScn);
      logger.info(ta.getName() + " applied rolling update in " + c.tick() + " ms");
      return true;
    } catch (Exception e) {
      logger.error(ta.getName() + " failed to update indexes", e);
    } finally {
      map.clear();
View Full Code Here


    File connectionsStoreDir = new File(args[4]);
    int connectionsStoreCapacity = Integer.parseInt(args[5]);
    int connectionsStoreSegmentMB = Integer.parseInt(args[6]);
    File elementScoreDir = (args.length > 7) ? new File(args[7]) : null;
   
    Chronos c = new Chronos();
   
    // Load elementStore
    SegmentFactory elementStoreSegFactory = new MemorySegmentFactory();
    ElementSerializer<TypeaheadElement> elementSerializer = new TypeaheadElementSerializer();
    ArrayStoreElement<TypeaheadElement> elementStore =
      StoreFactory.createElementStorePartition(elementStoreDir, idStart, idCount, elementStoreSegFactory, elementStoreSegMB, elementSerializer);
   
    // Load elementStore into memory
    elementStore = new MemoryArrayStoreElement<TypeaheadElement>(elementStore);
   
    // Load element scores
    if(elementStoreDir != null && elementScoreDir.exists()) {
      ElementScoreSetter<TypeaheadElement> handler = new ElementScoreSetter<TypeaheadElement>(elementStore);
      ElementScoreScanner scan = new ElementScoreScanner(elementScoreDir);
      scan.scan(handler);
    }
   
    // Create connectionsStore
    int indexSegmentFileSizeMB = 8;
    SegmentFactory indexSegmentFactory = new MemorySegmentFactory();
    SegmentFactory storeSegmentFactory = new MemorySegmentFactory();
    ConnectionsStore<String> connectionsStore =
      StoreFactory.createConnectionsStore(
          connectionsStoreDir, connectionsStoreCapacity,
          indexSegmentFileSizeMB, indexSegmentFactory,
          connectionsStoreSegmentMB, storeSegmentFactory);
   
    ConnectionsCollector connectionsCollector = new ConnectionsCollector(connectionsStoreCapacity);
    connectionsCollector.collect(elementStore, 5 /* maxKeyLength */);
    connectionsCollector.store(connectionsStore);
   
    System.out.printf("Bootstrap done in %d ms%n", c.tick());
  }
View Full Code Here

    line3Data = new String[elementStore.capacity()];
    mediaData = new String[elementStore.capacity()];
  }
 
  protected void loadData(File dataDir, String[] dataArray) {
    Chronos c = new Chronos();
    for(File f : dataDir.listFiles()) {
      if(f.isFile()) {
        try {
          loadDataFile(f, dataArray);
          System.out.printf("%s loaded in %d ms%n", f.getAbsolutePath(), c.tick());
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
View Full Code Here

    File line1Dir = new File(args[5]);
    File line2Dir = new File(args[6]);
    File line3Dir = new File(args[7]);
    File mediaDir = new File(args[8]);
   
    Chronos c = new Chronos();
   
    SegmentFactory elementStoreSegFactory = new MemorySegmentFactory();
    ElementFactory<TypeaheadElement> elementFactory = new SimpleTypeaheadElementFactory();
    ElementSerializer<TypeaheadElement> elementSerializer = new TypeaheadElementSerializer();
    ArrayStoreElement<TypeaheadElement> elementStore =
      StoreFactory.createElementStorePartition(elementStoreDir, idStart, idCount, elementStoreSegFactory, elementStoreSegMB, elementSerializer);
    TypeaheadElementStoreBootstrap elementStoreBootstrap =
      new TypeaheadElementStoreBootstrap(elementStore, elementFactory);
   
    elementStoreBootstrap.loadLine1(line1Dir);
    elementStoreBootstrap.loadLine2(line2Dir);
    elementStoreBootstrap.loadLine3(line3Dir);
    elementStoreBootstrap.loadMedia(mediaDir);
   
    TermsScanner scanner = new TermsScanner(termsDir);
    scanner.scan(new CompositeTermsHandler().add(new TermsDedup()).add(elementStoreBootstrap));
    elementStore.sync();
   
    System.out.printf("Bootstrap done in %d ms%n", c.tick());
  }
View Full Code Here

    int connSourceIdStart = Integer.parseInt(args[3]);
    int connSourceIdCount = Integer.parseInt(args[4]);
    int connTargetIdStart = Integer.parseInt(args[5]);
    int connTargetIdCount = Integer.parseInt(args[6]);
   
    Chronos c = new Chronos();
   
    // Create connectionsStore
    int capacity = connSourceIdCount;
    ArrayStoreConnections connectionsStore =
      StoreFactory.createArrayStoreConnections(connectionsStoreDir, capacity, connectionsStoreSegMB);
   
    // Bootstrap connectionsStore
    ArrayStoreConnectionsBootstrap bootstrap =
      new ArrayStoreConnectionsBootstrap(connectionsStore,
                                         connSourceIdStart,
                                         connSourceIdCount,
                                         connTargetIdStart,
                                         connTargetIdCount);
   
    ConnectionsScanner scanner = new ConnectionsScanner(connectionsDir);
    scanner.scan(bootstrap);
    connectionsStore.sync();
   
    System.out.printf("Bootstrap done in %d ms%n", c.tick());
  }
View Full Code Here

    try {
      connTargetIdStart = Integer.parseInt(args[5]);
      connTargetIdCount = Integer.parseInt(args[6]);
    } catch(Exception e) {}
   
    Chronos c = new Chronos();
   
    // Create connectionsStore
    int capacity = connSourceIdCount;
    ArrayStoreConnections connectionsStore =
      StoreFactory.createArrayStoreConnections(connectionsStoreDir, capacity, connectionsStoreSegMB);
   
    // Bootstrap connectionsStore
    ArrayStoreConnectionsBootstrap bootstrap =
      new ArrayStoreConnectionsBootstrap(connectionsStore,
                                         connSourceIdStart,
                                         connSourceIdCount,
                                         connTargetIdStart,
                                         connTargetIdCount);
   
    ConnectionsScanner scanner = new ConnectionsScanner(connectionsDir);
    scanner.scan(bootstrap);
    connectionsStore.sync();
   
    System.out.printf("Bootstrap done in %d ms%n", c.tick());
  }
View Full Code Here

   *
   * @param args
   * @throws Exception
   */
  public static void main(String args[]) throws Exception {
    Chronos c = new Chronos();
    MultiConnectionsHandler multiHandler = new MultiConnectionsHandler();
   
    File connectionsDir = new File(args[0]);
    long maxScn = Long.parseLong(args[1]);
    for(int i = 2; i < args.length; i++) {
      /**
       * Load bootstrap properties.
       */
      Properties properties = new Properties();
      try {
        String configFile = args[i];
        FileInputStream inStream = new FileInputStream(configFile);
        InputStreamReader reader = new InputStreamReader(inStream, "UTF-8");
        properties.load(reader);
        PropertiesResolver.resolve(properties);
        properties.list(System.out);
      } catch(Exception e) {
        e.printStackTrace();
        System.exit(1);
      }
     
      /**
       * Configure NetworkTypeahead
       */
      NetworkTypeaheadConfig<TypeaheadElement> config =
        TypeaheadConfigFactory.createNetworkTypeaheadConfig(properties);
      config.setElementStoreCached(false); // disable cache to bypass serialization
      config.setElementStoreSegmentFactory(new ChannelSegmentFactory());
      config.setConnectionsStoreSegmentFactory(new WriteBufferSegmentFactory(config.getConnectionsStoreSegmentMB()));
     
      WeightedNetworkTypeaheadInitializer<TypeaheadElement> initializer =
        new WeightedNetworkTypeaheadInitializer<TypeaheadElement>(config);
      WeightedNetworkTypeahead<TypeaheadElement> typeahead =
        (WeightedNetworkTypeahead<TypeaheadElement>) initializer.getTypeahead();

      ConnectionFilter connectionFilter = typeahead.getConnectionFilter();
      ArrayStoreWeights weightedConnectionsStore = typeahead.getConnectionsStore();
      System.out.printf("Added %s%n", config.getConnectionsStoreDir().getParent());
     
      multiHandler.add(new WeightedConnectionsStoreConnectionsHandler(weightedConnectionsStore, connectionFilter, maxScn));
    }
   
    if(multiHandler.isEmpty()) return;
   
    /**
     * Bootstrap weighted-connections-store
     */
    System.out.println("-- starting bootstrap --");
   
    ConnectionsScanner scanner = new ConnectionsScanner(connectionsDir);
    scanner.scan(multiHandler);
   
    Iterator<ConnectionsHandler> iter = multiHandler.iterator();
    while(iter.hasNext()) {
      ArrayStoreWeights weightedConnectionsStore;
      weightedConnectionsStore = ((WeightedConnectionsStoreConnectionsHandler)iter.next()).getWeightedConnectionsStore();
      weightedConnectionsStore.sync();
    }
   
    System.out.println();
    System.out.printf("Bootstrap done in %d seconds%n", c.getTotalTime()/1000);
  }
View Full Code Here

*/
public class GenericTypeaheadBootstrap {

  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws Exception {
    Chronos c = new Chronos();
   
    /**
     * Load bootstrap properties
     */
    String configFile = args[0];
    Properties properties = new Properties();
    FileInputStream inStream = new FileInputStream(configFile);
    InputStreamReader reader = new InputStreamReader(inStream, "UTF-8");
    properties.load(reader);
    PropertiesResolver.resolve(properties);
    properties.list(System.out);
   
    System.out.println("-- starting bootstrap --");
   
    File termsDir = new File(properties.getProperty("cleo.search.generic.typeahead.config.source.terms.dir"));
    File line1Dir = new File(properties.getProperty("cleo.search.generic.typeahead.config.source.line1.dir"));
    File line2Dir = new File(properties.getProperty("cleo.search.generic.typeahead.config.source.line2.dir"));
    File line3Dir = new File(properties.getProperty("cleo.search.generic.typeahead.config.source.line3.dir"));
    File mediaDir = new File(properties.getProperty("cleo.search.generic.typeahead.config.source.media.dir"));
    File scoreDir = new File(properties.getProperty("cleo.search.generic.typeahead.config.source.score.dir"));

    ElementFactory<TypeaheadElement> elementFactory = (ElementFactory<TypeaheadElement>)
      Class.forName(properties.getProperty("cleo.search.generic.typeahead.config.elementFactory.class")).newInstance();
   
    /**
     * Configure GenericTypeahead
     */
    GenericTypeaheadConfig<TypeaheadElement> config = TypeaheadConfigFactory.createGenericTypeaheadConfig(properties);
    System.out.printf("Initialize typeahead %s ...%n", config.getName());
   
    GenericTypeaheadInitializer<TypeaheadElement> initializer = new GenericTypeaheadInitializer<TypeaheadElement>(config);
    GenericTypeahead<TypeaheadElement> typeahead = (GenericTypeahead<TypeaheadElement>) initializer.getTypeahead();
   
    System.out.printf("Initialize typeahead %s: %d ms%n", config.getName(), c.tick());
   
    /**
     * Bootstrap element-store
     */
    ArrayStoreElement<TypeaheadElement> elementStore = typeahead.getElementStore();
    String elementStoreName = config.getElementStoreDir().getName();
    System.out.printf("Bootstrap %s ...%n", elementStoreName);
   
    TypeaheadElementStoreBootstrap elementStoreBootstrap =  new TypeaheadElementStoreBootstrap(elementStore, elementFactory);
   
    elementStoreBootstrap.loadLine1(line1Dir);
    elementStoreBootstrap.loadLine2(line2Dir);
    elementStoreBootstrap.loadLine3(line3Dir);
    elementStoreBootstrap.loadMedia(mediaDir);
   
    TermsScanner scanner = new TermsScanner(termsDir);
    scanner.scan(new CompositeTermsHandler().add(new TermsDedup()).add(elementStoreBootstrap));
    elementStore.sync();
   
    System.out.printf("Bootstrap %s: %d ms%n", elementStoreName, c.tick());
   
    /**
     * Bootstrap connections-store
     */
    ConnectionsStore<String> connectionsStore = typeahead.getConnectionsStore();
    String connectionsStoreName = config.getConnectionsStoreDir().getName();
    System.out.printf("Bootstrap %s ...%n", connectionsStoreName);
   
    // Load element scores
    if(scoreDir != null && scoreDir.exists()) {
      ElementScoreSetter<TypeaheadElement> handler = new ElementScoreSetter<TypeaheadElement>(elementStore);
      ElementScoreScanner scan = new ElementScoreScanner(scoreDir);
      scan.scan(handler);
    }
   
    ConnectionsCollector connectionsCollector = new ConnectionsCollector(config.getConnectionsStoreCapacity());
    connectionsCollector.collect(elementStore, config.getMaxKeyLength());
    connectionsCollector.store(connectionsStore);
   
    System.out.printf("Bootstrap %s: %d ms%n", connectionsStoreName, c.tick());
   
    System.out.println();
    System.out.printf("Total: %d seconds%n", c.getTotalTime()/1000);
  }
View Full Code Here

    } catch(Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
   
    Chronos c = new Chronos();
    NetworkTypeaheadConfig<TypeaheadElement> config;
    WeightedNetworkTypeaheadInitializer<TypeaheadElement> initializer;
   
    /**
     * Configure NetworkTypeahead
     */
    config = TypeaheadConfigFactory.createNetworkTypeaheadConfig(properties);
    config.setElementStoreCached(false); // disable cache to bypass serialization
    config.setElementStoreSegmentFactory(new ChannelSegmentFactory());
    config.setConnectionsStoreSegmentFactory(new ChannelSegmentFactory());
    initializer = new WeightedNetworkTypeaheadInitializer<TypeaheadElement>(config);
   
    WeightedNetworkTypeahead<TypeaheadElement> typeahead =
      (WeightedNetworkTypeahead<TypeaheadElement>) initializer.getTypeahead();
   
    // Set NetworkTypehead connections store hwMark
    typeahead.getConnectionsStore().saveHWMark(maxScn);
    typeahead.getConnectionsStore().sync();
   
    System.out.printf("Time: %d ms.%n", c.tick());
  }
View Full Code Here

    } catch(Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
   
    Chronos c = new Chronos();
    NetworkTypeaheadConfig<TypeaheadElement> config;
    VanillaNetworkTypeaheadInitializer<TypeaheadElement> initializer;
   
    /**
     * Configure source NetworkTypeahead
     */
    config = TypeaheadConfigFactory.createNetworkTypeaheadConfig(sourceProperties);
    config.setElementStoreCached(false); // disable cache to bypass serialization
    config.setElementStoreSegmentFactory(new MappedSegmentFactory());
    config.setConnectionsStoreSegmentFactory(new MappedSegmentFactory());
    initializer = new VanillaNetworkTypeaheadInitializer<TypeaheadElement>(config);
   
    VanillaNetworkTypeahead<TypeaheadElement> sourceTypeahead =
      (VanillaNetworkTypeahead<TypeaheadElement>) initializer.getTypeahead();
    long sourceLoadTime = c.tick();
   
    /**
     * Configure target NetworkTypeahead
     */
    config = TypeaheadConfigFactory.createNetworkTypeaheadConfig(targetProperties);
    config.setElementStoreCached(false); // disable cache to bypass serialization
    config.setElementStoreSegmentFactory(new MappedSegmentFactory());
    config.setConnectionsStoreSegmentFactory(new WriteBufferSegmentFactory(config.getConnectionsStoreSegmentMB()));
    initializer = new VanillaNetworkTypeaheadInitializer<TypeaheadElement>(config);
   
    VanillaNetworkTypeahead<TypeaheadElement> targetTypeahead =
      (VanillaNetworkTypeahead<TypeaheadElement>) initializer.getTypeahead();
    long targetLoadTime = c.tick();
   
    // Set target NetworkTypehead connections store hwMark before copying.
    targetTypeahead.getConnectionsStore().saveHWMark(targetConnectionsStoreHWMark);
   
    // Copy now!
    Copy.copy(sourceTypeahead, targetTypeahead);
    long copyTime = c.tick();
   
    // Set target NetworkTypehead connections store hwMark after copying and then sync.
    targetTypeahead.getConnectionsStore().saveHWMark(targetConnectionsStoreHWMark);
    targetTypeahead.getConnectionsStore().sync();
   
View Full Code Here

TOP

Related Classes of krati.util.Chronos

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.