Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.splout.db.dnode;
   * #%L
   * Splout SQL Server
   * %%
   * Copyright (C) 2012 Datasalt Systems S.L.
   * %%
   * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * GNU General Public License for more details.
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <>.
  * #L%
 import java.util.List;
 import  org.apache.thrift.TException;
 import  org.apache.thrift.server.THsHaServer;
 import  org.apache.thrift.server.TServer;
 import  org.apache.thrift.transport.TNonblockingServerSocket;
 import  org.apache.thrift.transport.TNonblockingServerTransport;
The Thrift skeleton for the DNode service. This class only implements the Thrift logic.

The DNode's own business logic is packed into DNodeHandler which is an implementation of IDNodeHandler. In this way, we can use the DNode in unit tests by using Mock implementations of IDNodeHandler.

 public class DNode implements DNodeService.Iface {
 	private final static Log log = LogFactory.getLog(DNode.class);
 	private IDNodeHandler handler;
 	private TServer server;
 	private Thread servingThread;
 	public DNode(SploutConfiguration configIDNodeHandler handler) {
 		this. = handler;
 		this. = config;

Returns the address (host:port) of this DNode.
 	public String getAddress() {

Initialize the DNode service - the important thing here is to instantiate a multi-threaded Thrift server. Everything is based on the given SploutConfiguration by constructor.
 	@SuppressWarnings({ "unchecked""rawtypes" })
 	public void init() throws Exception {
 		DNodeService.Processor processor = new DNodeService.Processor(this);
 		TNonblockingServerTransport serverTransport = null;
 		boolean init = false;
 		int retries = 0;
 		int thriftPort;
 		do {
 			thriftPort = .getInt(.);
 			try {
 				serverTransport = new TNonblockingServerSocket(thriftPort);
 				init = true;
 			} catch(org.apache.thrift.transport.TTransportException e) {
 					throw e;
 				.setProperty(.thriftPort + 1);
 		} while(!init && retries < 100);
 		THsHaServer.Args args = new THsHaServer.Args(serverTransport);
		 = new THsHaServer(args);
		// We instantiate a long-living serving thread that will use the Thrift server.
		 = new Thread("Serving Thread") {
			public void run() {
				try {
catch(Throwable t) {
		.info("Thrift server started on port: " + thriftPort);
	// ---- The following methods are a facade for {@link IDNodeHandler} ---- //
	public String sqlQuery(String tablespacelong versionint partitionString query)
	    throws DNodeException, TException {
		return .sqlQuery(tablespaceversionpartitionquery);
	public String deploy(List<DeployActiondeployActionslong versionthrows DNodeException, TException {
		return .deploy(deployActionsversion);
	public String rollback(List<RollbackActionrollbackActionsString distributedBarrier)
	    throws DNodeException, TException {
		return .rollback(rollbackActionsdistributedBarrier);
	public String status() throws DNodeException, TException {
		return .status();
	public void stop() throws Exception {
	public static void main(String[] argsthrows Exception {
		if(args.length == 1) {
			// config root
			config = SploutConfiguration.get(args[0]);
else {
			config = SploutConfiguration.get();
		DNode dnode = new DNode(confignew DNodeHandler());
	public String abortDeploy(long versionthrows DNodeException, TException {
		return .abortDeploy(version);
	public String deleteOldVersions(List<TablespaceVersionversionsthrows DNodeException, TException {
		return .deleteOldVersions(versions);
  public String testCommand(String commandthrows DNodeException, TException {
	  return .testCommand(command);
New to GrepCode? Check out our FAQ X