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) {
 | 
			
		||||
        log.trace("[{}] Sending downlink msg [{}]", this.sessionId, downlinkMsg);
 | 
			
		||||
        if (isConnected()) {
 | 
			
		||||
            try {
 | 
			
		||||
            downlinkMsgLock.lock();
 | 
			
		||||
            try {
 | 
			
		||||
                outputStream.onNext(downlinkMsg);
 | 
			
		||||
            } catch (Exception 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 {
 | 
			
		||||
        try {
 | 
			
		||||
        downlinkMsgsPackLock.lock();
 | 
			
		||||
        try {
 | 
			
		||||
            boolean success;
 | 
			
		||||
            pendingMsgsMap.clear();
 | 
			
		||||
            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) {
 | 
			
		||||
        Device device;
 | 
			
		||||
        try {
 | 
			
		||||
        deviceCreationLock.lock();
 | 
			
		||||
        try {
 | 
			
		||||
            log.debug("[{}] Creating device entity [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName());
 | 
			
		||||
            DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
 | 
			
		||||
            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) {
 | 
			
		||||
        jsPushedMsgs.incrementAndGet();
 | 
			
		||||
        ListenableFuture<UUID> result = jsExecutor.executeAsync(() -> {
 | 
			
		||||
            try {
 | 
			
		||||
            evalLock.lock();
 | 
			
		||||
            try {
 | 
			
		||||
                try {
 | 
			
		||||
                    if (useJsSandbox()) {
 | 
			
		||||
                        sandbox.eval(jsScript);
 | 
			
		||||
 | 
			
		||||
@ -275,8 +275,8 @@ public class EdgeImitator {
 | 
			
		||||
 | 
			
		||||
    private ListenableFuture<Void> saveDownlinkMsg(AbstractMessage message) {
 | 
			
		||||
        if (!ignoredTypes.contains(message.getClass())) {
 | 
			
		||||
            try {
 | 
			
		||||
            lock.lock();
 | 
			
		||||
            try {
 | 
			
		||||
                downlinkMsgs.add(message);
 | 
			
		||||
            } finally {
 | 
			
		||||
                lock.unlock();
 | 
			
		||||
@ -312,8 +312,8 @@ public class EdgeImitator {
 | 
			
		||||
    @SuppressWarnings("unchecked")
 | 
			
		||||
    public <T extends AbstractMessage> Optional<T> findMessageByType(Class<T> tClass) {
 | 
			
		||||
        Optional<T> result;
 | 
			
		||||
        try {
 | 
			
		||||
        lock.lock();
 | 
			
		||||
        try {
 | 
			
		||||
            result = (Optional<T>) downlinkMsgs.stream().filter(downlinkMsg -> downlinkMsg.getClass().isAssignableFrom(tClass)).findAny();
 | 
			
		||||
        } finally {
 | 
			
		||||
            lock.unlock();
 | 
			
		||||
@ -324,8 +324,8 @@ public class EdgeImitator {
 | 
			
		||||
    @SuppressWarnings("unchecked")
 | 
			
		||||
    public <T extends AbstractMessage> List<T> findAllMessagesByType(Class<T> tClass) {
 | 
			
		||||
        List<T> result;
 | 
			
		||||
        try {
 | 
			
		||||
        lock.lock();
 | 
			
		||||
        try {
 | 
			
		||||
            result = (List<T>) downlinkMsgs.stream().filter(downlinkMsg -> downlinkMsg.getClass().isAssignableFrom(tClass)).collect(Collectors.toList());
 | 
			
		||||
        } finally {
 | 
			
		||||
            lock.unlock();
 | 
			
		||||
 | 
			
		||||
@ -185,8 +185,8 @@ public class EdgeGrpcClient implements EdgeRpcClient {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendUplinkMsg(UplinkMsg msg) {
 | 
			
		||||
        try {
 | 
			
		||||
        uplinkMsgLock.lock();
 | 
			
		||||
        try {
 | 
			
		||||
            this.inputStream.onNext(RequestMsg.newBuilder()
 | 
			
		||||
                    .setMsgType(RequestMsgType.UPLINK_RPC_MESSAGE)
 | 
			
		||||
                    .setUplinkMsg(msg)
 | 
			
		||||
@ -198,8 +198,8 @@ public class EdgeGrpcClient implements EdgeRpcClient {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendSyncRequestMsg(boolean syncRequired) {
 | 
			
		||||
        try {
 | 
			
		||||
        uplinkMsgLock.lock();
 | 
			
		||||
        try {
 | 
			
		||||
            SyncRequestMsg syncRequestMsg = SyncRequestMsg.newBuilder().setSyncRequired(syncRequired).build();
 | 
			
		||||
            this.inputStream.onNext(RequestMsg.newBuilder()
 | 
			
		||||
                    .setMsgType(RequestMsgType.SYNC_REQUEST_RPC_MESSAGE)
 | 
			
		||||
@ -212,8 +212,8 @@ public class EdgeGrpcClient implements EdgeRpcClient {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendDownlinkResponseMsg(DownlinkResponseMsg downlinkResponseMsg) {
 | 
			
		||||
        try {
 | 
			
		||||
        uplinkMsgLock.lock();
 | 
			
		||||
        try {
 | 
			
		||||
            this.inputStream.onNext(RequestMsg.newBuilder()
 | 
			
		||||
                    .setMsgType(RequestMsgType.UPLINK_RPC_MESSAGE)
 | 
			
		||||
                    .setDownlinkResponseMsg(downlinkResponseMsg)
 | 
			
		||||
 | 
			
		||||
@ -248,8 +248,8 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
 | 
			
		||||
        log.trace("Executing findOrCreateDefaultDeviceProfile");
 | 
			
		||||
        DeviceProfile deviceProfile = findDeviceProfileByName(tenantId, name);
 | 
			
		||||
        if (deviceProfile == null) {
 | 
			
		||||
            try {
 | 
			
		||||
            findOrCreateLock.lock();
 | 
			
		||||
            try {
 | 
			
		||||
                deviceProfile = findDeviceProfileByName(tenantId, name);
 | 
			
		||||
                if (deviceProfile == null) {
 | 
			
		||||
                    deviceProfile = this.doCreateDefaultDeviceProfile(tenantId, name, name.equals("default"));
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user