Skip to content

Commit

Permalink
Supported configurable execution mode for commands (local or distribu…
Browse files Browse the repository at this point in the history
…ted)
  • Loading branch information
lvca committed Oct 2, 2015
1 parent 71697fe commit 2595925
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.OCommandSQLParsingException;
import com.orientechnologies.orient.core.storage.ORecordDuplicatedException;
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation;
import com.orientechnologies.orient.core.tx.OTransaction;

import javax.script.*;
import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
* Executes Script Commands.
Expand All @@ -56,20 +66,22 @@
*
*/
public class OCommandExecutorScript extends OCommandExecutorAbstract implements OCommandDistributedReplicateRequest {
private static final int MAX_DELAY = 100;
protected OCommandScript request;
private static final int MAX_DELAY = 100;
protected OCommandScript request;
protected DISTRIBUTED_EXECUTION_MODE executionMode = DISTRIBUTED_EXECUTION_MODE.LOCAL;

public OCommandExecutorScript() {
}

@SuppressWarnings("unchecked")
public OCommandExecutorScript parse(final OCommandRequest iRequest) {
request = (OCommandScript) iRequest;
executionMode = ((OCommandScript) iRequest).getExecutionMode();
return this;
}

public OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.LOCAL;
return executionMode;
}

public Object execute(final Map<Object, Object> iArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
*/
package com.orientechnologies.orient.core.command.script;

import javax.script.CompiledScript;

import com.orientechnologies.orient.core.command.OCommandDistributedReplicateRequest;
import com.orientechnologies.orient.core.command.OCommandRequestTextAbstract;
import com.orientechnologies.orient.core.exception.OSerializationException;
import com.orientechnologies.orient.core.serialization.OMemoryStream;
import com.orientechnologies.orient.core.serialization.OSerializableStream;

import javax.script.CompiledScript;

/**
* Script command request implementation. It just stores the request and delegated the execution to the configured OCommandExecutor.
*
Expand All @@ -36,8 +37,10 @@
*/
@SuppressWarnings("serial")
public class OCommandScript extends OCommandRequestTextAbstract {
private String language;
private CompiledScript compiledScript;
private String language;
private CompiledScript compiledScript;

private OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE executionMode = OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE.LOCAL;

public OCommandScript() {
useCache = true;
Expand Down Expand Up @@ -72,13 +75,15 @@ public OCommandScript setLanguage(String language) {
public OSerializableStream fromStream(byte[] iStream) throws OSerializationException {
final OMemoryStream buffer = new OMemoryStream(iStream);
language = buffer.getAsString();
executionMode = OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE.valueOf(buffer.getAsString());
fromStream(buffer);
return this;
}

public byte[] toStream() throws OSerializationException {
final OMemoryStream buffer = new OMemoryStream();
buffer.setUtf8(language);
buffer.setUtf8(executionMode.name());
return toStream(buffer);
}

Expand All @@ -96,4 +101,13 @@ public String toString() {
return language + "." + text;
return "script." + text;
}

public OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE getExecutionMode() {
return executionMode;
}

public OCommandScript setExecutionMode(OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE executionMode) {
this.executionMode = executionMode;
return this;
}
}

0 comments on commit 2595925

Please # to comment.