Code review fixes - moved out .lock from try block
This commit is contained in:
parent
11a7fc68e3
commit
3319154513
@ -280,8 +280,8 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
private void sendDownlinkMsg(ResponseMsg downlinkMsg) {
|
private void sendDownlinkMsg(ResponseMsg downlinkMsg) {
|
||||||
log.trace("[{}] Sending downlink msg [{}]", this.sessionId, downlinkMsg);
|
log.trace("[{}] Sending downlink msg [{}]", this.sessionId, downlinkMsg);
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
try {
|
|
||||||
downlinkMsgLock.lock();
|
downlinkMsgLock.lock();
|
||||||
|
try {
|
||||||
outputStream.onNext(downlinkMsg);
|
outputStream.onNext(downlinkMsg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[{}] Failed to send downlink message [{}]", this.sessionId, downlinkMsg, e);
|
log.error("[{}] Failed to send downlink message [{}]", this.sessionId, downlinkMsg, e);
|
||||||
@ -345,8 +345,8 @@ public final class EdgeGrpcSession implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendDownlinkMsgsPack(List<DownlinkMsg> downlinkMsgsPack) throws InterruptedException {
|
private boolean sendDownlinkMsgsPack(List<DownlinkMsg> downlinkMsgsPack) throws InterruptedException {
|
||||||
try {
|
|
||||||
downlinkMsgsPackLock.lock();
|
downlinkMsgsPackLock.lock();
|
||||||
|
try {
|
||||||
boolean success;
|
boolean success;
|
||||||
pendingMsgsMap.clear();
|
pendingMsgsMap.clear();
|
||||||
downlinkMsgsPack.forEach(msg -> pendingMsgsMap.put(msg.getDownlinkMsgId(), msg));
|
downlinkMsgsPack.forEach(msg -> pendingMsgsMap.put(msg.getDownlinkMsgId(), msg));
|
||||||
|
|||||||
@ -189,8 +189,8 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
|
|||||||
|
|
||||||
private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg, String deviceName) {
|
private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg, String deviceName) {
|
||||||
Device device;
|
Device device;
|
||||||
try {
|
|
||||||
deviceCreationLock.lock();
|
deviceCreationLock.lock();
|
||||||
|
try {
|
||||||
log.debug("[{}] Creating device entity [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName());
|
log.debug("[{}] Creating device entity [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName());
|
||||||
DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
|
DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
|
||||||
device = deviceService.findDeviceById(tenantId, deviceId);
|
device = deviceService.findDeviceById(tenantId, deviceId);
|
||||||
|
|||||||
@ -124,8 +124,8 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
|
|||||||
protected ListenableFuture<UUID> doEval(UUID scriptId, String functionName, String jsScript) {
|
protected ListenableFuture<UUID> doEval(UUID scriptId, String functionName, String jsScript) {
|
||||||
jsPushedMsgs.incrementAndGet();
|
jsPushedMsgs.incrementAndGet();
|
||||||
ListenableFuture<UUID> result = jsExecutor.executeAsync(() -> {
|
ListenableFuture<UUID> result = jsExecutor.executeAsync(() -> {
|
||||||
try {
|
|
||||||
evalLock.lock();
|
evalLock.lock();
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
if (useJsSandbox()) {
|
if (useJsSandbox()) {
|
||||||
sandbox.eval(jsScript);
|
sandbox.eval(jsScript);
|
||||||
|
|||||||
@ -275,8 +275,8 @@ public class EdgeImitator {
|
|||||||
|
|
||||||
private ListenableFuture<Void> saveDownlinkMsg(AbstractMessage message) {
|
private ListenableFuture<Void> saveDownlinkMsg(AbstractMessage message) {
|
||||||
if (!ignoredTypes.contains(message.getClass())) {
|
if (!ignoredTypes.contains(message.getClass())) {
|
||||||
try {
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
try {
|
||||||
downlinkMsgs.add(message);
|
downlinkMsgs.add(message);
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
@ -312,8 +312,8 @@ public class EdgeImitator {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends AbstractMessage> Optional<T> findMessageByType(Class<T> tClass) {
|
public <T extends AbstractMessage> Optional<T> findMessageByType(Class<T> tClass) {
|
||||||
Optional<T> result;
|
Optional<T> result;
|
||||||
try {
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
try {
|
||||||
result = (Optional<T>) downlinkMsgs.stream().filter(downlinkMsg -> downlinkMsg.getClass().isAssignableFrom(tClass)).findAny();
|
result = (Optional<T>) downlinkMsgs.stream().filter(downlinkMsg -> downlinkMsg.getClass().isAssignableFrom(tClass)).findAny();
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
@ -324,8 +324,8 @@ public class EdgeImitator {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends AbstractMessage> List<T> findAllMessagesByType(Class<T> tClass) {
|
public <T extends AbstractMessage> List<T> findAllMessagesByType(Class<T> tClass) {
|
||||||
List<T> result;
|
List<T> result;
|
||||||
try {
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
try {
|
||||||
result = (List<T>) downlinkMsgs.stream().filter(downlinkMsg -> downlinkMsg.getClass().isAssignableFrom(tClass)).collect(Collectors.toList());
|
result = (List<T>) downlinkMsgs.stream().filter(downlinkMsg -> downlinkMsg.getClass().isAssignableFrom(tClass)).collect(Collectors.toList());
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|||||||
@ -185,8 +185,8 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendUplinkMsg(UplinkMsg msg) {
|
public void sendUplinkMsg(UplinkMsg msg) {
|
||||||
try {
|
|
||||||
uplinkMsgLock.lock();
|
uplinkMsgLock.lock();
|
||||||
|
try {
|
||||||
this.inputStream.onNext(RequestMsg.newBuilder()
|
this.inputStream.onNext(RequestMsg.newBuilder()
|
||||||
.setMsgType(RequestMsgType.UPLINK_RPC_MESSAGE)
|
.setMsgType(RequestMsgType.UPLINK_RPC_MESSAGE)
|
||||||
.setUplinkMsg(msg)
|
.setUplinkMsg(msg)
|
||||||
@ -198,8 +198,8 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendSyncRequestMsg(boolean syncRequired) {
|
public void sendSyncRequestMsg(boolean syncRequired) {
|
||||||
try {
|
|
||||||
uplinkMsgLock.lock();
|
uplinkMsgLock.lock();
|
||||||
|
try {
|
||||||
SyncRequestMsg syncRequestMsg = SyncRequestMsg.newBuilder().setSyncRequired(syncRequired).build();
|
SyncRequestMsg syncRequestMsg = SyncRequestMsg.newBuilder().setSyncRequired(syncRequired).build();
|
||||||
this.inputStream.onNext(RequestMsg.newBuilder()
|
this.inputStream.onNext(RequestMsg.newBuilder()
|
||||||
.setMsgType(RequestMsgType.SYNC_REQUEST_RPC_MESSAGE)
|
.setMsgType(RequestMsgType.SYNC_REQUEST_RPC_MESSAGE)
|
||||||
@ -212,8 +212,8 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendDownlinkResponseMsg(DownlinkResponseMsg downlinkResponseMsg) {
|
public void sendDownlinkResponseMsg(DownlinkResponseMsg downlinkResponseMsg) {
|
||||||
try {
|
|
||||||
uplinkMsgLock.lock();
|
uplinkMsgLock.lock();
|
||||||
|
try {
|
||||||
this.inputStream.onNext(RequestMsg.newBuilder()
|
this.inputStream.onNext(RequestMsg.newBuilder()
|
||||||
.setMsgType(RequestMsgType.UPLINK_RPC_MESSAGE)
|
.setMsgType(RequestMsgType.UPLINK_RPC_MESSAGE)
|
||||||
.setDownlinkResponseMsg(downlinkResponseMsg)
|
.setDownlinkResponseMsg(downlinkResponseMsg)
|
||||||
|
|||||||
@ -248,8 +248,8 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
|
|||||||
log.trace("Executing findOrCreateDefaultDeviceProfile");
|
log.trace("Executing findOrCreateDefaultDeviceProfile");
|
||||||
DeviceProfile deviceProfile = findDeviceProfileByName(tenantId, name);
|
DeviceProfile deviceProfile = findDeviceProfileByName(tenantId, name);
|
||||||
if (deviceProfile == null) {
|
if (deviceProfile == null) {
|
||||||
try {
|
|
||||||
findOrCreateLock.lock();
|
findOrCreateLock.lock();
|
||||||
|
try {
|
||||||
deviceProfile = findDeviceProfileByName(tenantId, name);
|
deviceProfile = findDeviceProfileByName(tenantId, name);
|
||||||
if (deviceProfile == null) {
|
if (deviceProfile == null) {
|
||||||
deviceProfile = this.doCreateDefaultDeviceProfile(tenantId, name, name.equals("default"));
|
deviceProfile = this.doCreateDefaultDeviceProfile(tenantId, name, name.equals("default"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user