Package de.linwave.gtm.spring.server

Source Code of de.linwave.gtm.spring.server.GTMServiceImpl

package de.linwave.gtm.spring.server;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.odbms.ObjectContainer;
import org.odbms.ObjectSet;
import org.odbms.Query;

import de.linwave.gtm.GTM;
import de.linwave.gtm.ObjectTraverser;
import de.linwave.gtm.QueryImpl;

public class GTMServiceImpl implements GTMService
{
  ObjectContainer db = GTM.getInstance();

  private static final AtomicInteger threadCount = new AtomicInteger();
  private static final AtomicLong totals = new AtomicLong();
  private static final AtomicLong totalsInInterval = new AtomicLong();
  private static final AtomicLong t1 = new AtomicLong(System.currentTimeMillis());

  public String echo(String s)
  {
    int tc = threadCount.incrementAndGet();

    long totalInInterval = totalsInInterval.incrementAndGet();
    if (totalInInterval % 10000 == 0) {
      double td = (double) System.currentTimeMillis() - t1.longValue();
      double totalPerMs = ((double) totalInInterval / td);
      System.out.println("Throughput: " + totalPerMs + " entries per ms.");
      // reset counter/timer
      totalsInInterval.set(0);
      t1.set(System.currentTimeMillis());
    }

    long total = totals.incrementAndGet();
    if (total % 1000 == 0)
      System.out.println("Total calls: " + total + "  threadCount: " + tc);

    String ret = "Remote GTMServiceImpl: totals=" + total + " threadCnt=" + tc + " echo=" + s;
    db.store(new Info(ret));

    threadCount.decrementAndGet();

    return ret;
  }

  /**
   *
   */
  public boolean isIndexed(Class clasz, String fieldName)
  {
    return ObjectTraverser.getFieldInfo(clasz, fieldName).isIndexed;
  }

  /**
   * Store a Object in the DB
   */
  public long store(Object obj)
  {
    return db.store(obj);
  }

  public void refresh(Object obj)
  {
    db.refresh(obj, GTM.MAX_RECURSION_LEVEL);
  }

  public void refresh(Object obj, int depth)
  {
    db.refresh(obj, depth);
  }

  public void delete(Object obj)
  {
    db.delete(obj);
  }

  public void deleteCascade(Object obj)
  {
    db.deleteCascade(obj);
  }

  public <E> E getByID(Class<?> clasz, long oid)
  {
    return db.getByID(clasz, oid);
  }

  // public <E> Query query(Class<E> clasz)
  // {
  // return db.query(clasz);
  // }

  // public <E> Query query(Predicate<E> predicate)
  // {
  // return db.query(predicate);
  // }
  //
  // public <E> Query query(Predicate<E> predicate, Comparator<E> comp)
  // {
  // return db.query(predicate, comp);
  // }

  public <E> ObjectSet<E> queryByExample(Object obj)
  {
    ObjectSet<E> os = db.queryByExample(obj);

    return os;
  }

  public <E> ObjectSet<E> queryByExample(Object obj, int depth)
  {
    return db.queryByExample(obj, depth);
  }

  public long deleteClass(Class<?> clasz)
  {
    return db.deleteClass(clasz);
  }

  public <E> Query query(Class clasz)
  {
    QueryImpl query = new QueryImpl(clasz, true);
    return query;
  }
}
TOP

Related Classes of de.linwave.gtm.spring.server.GTMServiceImpl

TOP
Copyright © 2018 www.massapi.com. 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.