Refactoring
This commit is contained in:
commit
175e73256d
@ -143,28 +143,29 @@ public class ZkDiscoveryService implements DiscoveryService, PathChildrenCacheLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean reconnectInProgress = false;
|
private ConnectionStateListener checkReconnect(ServerInstance self) {
|
||||||
|
|
||||||
private synchronized ConnectionStateListener checkReconnect(ServerInstance self) {
|
|
||||||
return (client, newState) -> {
|
return (client, newState) -> {
|
||||||
log.info("[{}:{}] ZK state changed: {}", self.getHost(), self.getPort(), newState);
|
log.info("[{}:{}] ZK state changed: {}", self.getHost(), self.getPort(), newState);
|
||||||
if (newState == ConnectionState.LOST) {
|
if (newState == ConnectionState.LOST) {
|
||||||
if (!reconnectInProgress) {
|
reconnect();
|
||||||
reconnectInProgress = true;
|
|
||||||
reconnect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reconnect() {
|
private boolean reconnectInProgress = false;
|
||||||
try {
|
|
||||||
client.blockUntilConnected();
|
private synchronized void reconnect() {
|
||||||
} catch (InterruptedException e) {
|
if (!reconnectInProgress) {
|
||||||
log.error("Failed to reconnect to ZK: {}", e.getMessage(), e);
|
reconnectInProgress = true;
|
||||||
|
try {
|
||||||
|
client.blockUntilConnected();
|
||||||
|
publishCurrentServer();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("Failed to reconnect to ZK: {}", e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
reconnectInProgress = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
publishCurrentServer();
|
|
||||||
reconnectInProgress = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -18,22 +18,24 @@ package org.thingsboard.server.service.script;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ConditionalOnProperty(prefix = "js", value = "evaluator", havingValue = "local", matchIfMissing = true)
|
||||||
@Service
|
@Service
|
||||||
public class NashornJsInvokeService extends AbstractNashornJsInvokeService {
|
public class NashornJsInvokeService extends AbstractNashornJsInvokeService {
|
||||||
|
|
||||||
@Value("${actors.rule.js_sandbox.use_js_sandbox}")
|
@Value("${js.local.use_js_sandbox}")
|
||||||
private boolean useJsSandbox;
|
private boolean useJsSandbox;
|
||||||
|
|
||||||
@Value("${actors.rule.js_sandbox.monitor_thread_pool_size}")
|
@Value("${js.local.js_sandbox.monitor_thread_pool_size}")
|
||||||
private int monitorThreadPoolSize;
|
private int monitorThreadPoolSize;
|
||||||
|
|
||||||
@Value("${actors.rule.js_sandbox.max_cpu_time}")
|
@Value("${js.local.js_sandbox.max_cpu_time}")
|
||||||
private long maxCpuTime;
|
private long maxCpuTime;
|
||||||
|
|
||||||
@Value("${actors.rule.js_sandbox.max_errors}")
|
@Value("${js.local.js_sandbox.max_errors}")
|
||||||
private int maxErrors;
|
private int maxErrors;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2018 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.service.script;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@ConditionalOnProperty(prefix = "js", value = "evaluator", havingValue = "local", matchIfMissing = true)
|
||||||
|
@Service
|
||||||
|
public class RemoteJsInvokeService implements JsInvokeService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<UUID> eval(JsScriptType scriptType, String scriptBody, String... argNames) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<Object> invokeFunction(UUID scriptId, EntityId entityId, Object... args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<Void> release(UUID scriptId, EntityId entityId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -246,15 +246,6 @@ actors:
|
|||||||
allow_system_mail_service: "${ACTORS_RULE_ALLOW_SYSTEM_MAIL_SERVICE:true}"
|
allow_system_mail_service: "${ACTORS_RULE_ALLOW_SYSTEM_MAIL_SERVICE:true}"
|
||||||
# Specify thread pool size for external call service
|
# Specify thread pool size for external call service
|
||||||
external_call_thread_pool_size: "${ACTORS_RULE_EXTERNAL_CALL_THREAD_POOL_SIZE:10}"
|
external_call_thread_pool_size: "${ACTORS_RULE_EXTERNAL_CALL_THREAD_POOL_SIZE:10}"
|
||||||
js_sandbox:
|
|
||||||
# Use Sandboxed (secured) JavaScript environment
|
|
||||||
use_js_sandbox: "${ACTORS_RULE_JS_SANDBOX_USE_JS_SANDBOX:true}"
|
|
||||||
# Specify thread pool size for JavaScript sandbox resource monitor
|
|
||||||
monitor_thread_pool_size: "${ACTORS_RULE_JS_SANDBOX_MONITOR_THREAD_POOL_SIZE:4}"
|
|
||||||
# Maximum CPU time in milliseconds allowed for script execution
|
|
||||||
max_cpu_time: "${ACTORS_RULE_JS_SANDBOX_MAX_CPU_TIME:100}"
|
|
||||||
# Maximum allowed JavaScript execution errors before JavaScript will be blacklisted
|
|
||||||
max_errors: "${ACTORS_RULE_JS_SANDBOX_MAX_ERRORS:3}"
|
|
||||||
chain:
|
chain:
|
||||||
# Errors for particular actor are persisted once per specified amount of milliseconds
|
# Errors for particular actor are persisted once per specified amount of milliseconds
|
||||||
error_persist_frequency: "${ACTORS_RULE_CHAIN_ERROR_FREQUENCY:3000}"
|
error_persist_frequency: "${ACTORS_RULE_CHAIN_ERROR_FREQUENCY:3000}"
|
||||||
@ -413,6 +404,20 @@ audit_log:
|
|||||||
state:
|
state:
|
||||||
defaultInactivityTimeoutInSec: 10
|
defaultInactivityTimeoutInSec: 10
|
||||||
defaultStateCheckIntervalInSec: 10
|
defaultStateCheckIntervalInSec: 10
|
||||||
# TODO in v2.1
|
|
||||||
# defaultStatePersistenceIntervalInSec: 60
|
js:
|
||||||
# defaultStatePersistencePack: 100
|
evaluator: "${JS_EVALUATOR:external}" # local/external
|
||||||
|
# Built-in JVM JavaScript environment properties
|
||||||
|
local:
|
||||||
|
# Use Sandboxed (secured) JVM JavaScript environment
|
||||||
|
use_js_sandbox: "${USE_LOCAL_JS_SANDBOX:true}"
|
||||||
|
# Specify thread pool size for JavaScript sandbox resource monitor
|
||||||
|
monitor_thread_pool_size: "${LOCAL_JS_SANDBOX_MONITOR_THREAD_POOL_SIZE:4}"
|
||||||
|
# Maximum CPU time in milliseconds allowed for script execution
|
||||||
|
max_cpu_time: "${LOCAL_JS_SANDBOX_MAX_CPU_TIME:100}"
|
||||||
|
# Maximum allowed JavaScript execution errors before JavaScript will be blacklisted
|
||||||
|
max_errors: "${LOCAL_JS_SANDBOX_MAX_ERRORS:3}"
|
||||||
|
# Remote JavaScript environment properties
|
||||||
|
remote:
|
||||||
|
# Use Sandboxed (secured) JVM JavaScript environment
|
||||||
|
use_js_sandbox: "${USE_REMOTE_JS_SANDBOX:true}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user