Package net.ameba.cassandra.web.service

Source Code of net.ameba.cassandra.web.service.CassandraService

package net.ameba.cassandra.web.service;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.stereotype.Service;

/**
* Common functions
*
*/
@Service
public class CassandraService {

  private static String[] systemKeyspaces = new String[] {"system","definitions"};
 
  // background executor
  private ExecutorService backgroundExecutor;
 
  public CassandraService() {
    backgroundExecutor = Executors.newCachedThreadPool(new ThreadFactory() {
      private AtomicInteger idCounter = new AtomicInteger();
      @Override
      public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setName("CassandraWebConsoleExecutor-" + idCounter.incrementAndGet());
        thread.setDaemon(true);
        return thread;
      }
    });
  }

  /**
   * Check the keyspace is system or not.
   *
   * @param keyspaceName
   * @return
   */
  public boolean isSystemKeyspace(String keyspaceName) {
    for (int i = 0; i < systemKeyspaces.length; i++) {
      if (systemKeyspaces[i].equals(keyspaceName)) {
        return true;
      }
    }
    return false;
  }
 
  /**
   * Schedule background execution
   *
   * @param runnable
   */
  public void scheduleExecution(Runnable runnable) {
    backgroundExecutor.submit(runnable);
  }
}
TOP

Related Classes of net.ameba.cassandra.web.service.CassandraService

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.