org.eclipse.jdt.annotation.Nullable Java Examples

The following examples show how to use org.eclipse.jdt.annotation.Nullable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReflexDriver.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
public @Nullable List<Action> match(ReflexDriverContext ctx, byte[] protocol) {
   if (notification) {
      parseIasZoneStatusChangeNotification(ctx, protocol);
      if (matchesIasZoneStatusChangeNotification(ctx)) {
         return actions;
      }
   }

   if (attr) {
      parseIasZoneAttributes(ctx, protocol);
      if (matchesIasZoneAttributes(ctx)) {
         return actions;
      }
   }

   return null;
}
 
Example #2
Source File: HubAttributeReporter.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public HubAttributeReporter(Port port) {
   this.port = port;
   this.reporter = new PeriodicReporter();

   this.expectedSetAttributesLock = new ReentrantLock();
   this.expectedSetAttributes = new AtomicReference<>();
   this.aggregateReports = new HashMap<>();

   HubAttributesService.updates().subscribeOn(RxIris.io).retry().subscribe(new rx.Subscriber<HubAttributesService.UpdatedAttribute>() {
      @Override
      public void onNext(@Nullable UpdatedAttribute updated) {
         HubAttributesService.Attribute<?> attr = (updated != null) ? updated.getAttr() : null;
         if (attr != null) {
            hubAttributeUpdated(attr);
         }
      }

      @Override public void onError(@Nullable Throwable e) { }
      @Override public void onCompleted() { }
   });
}
 
Example #3
Source File: SQLite3StatementBindInvoker.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Object bind(SQLiteStatement stmt, Class<?> type, int index) {
   try {
      if (type.equals(String.class)) {
         return stmt.columnString(index);
      } else if (type.equals(Integer.class) || type.equals(int.class) ) {
         return stmt.columnInt(index);
      } else if (type.equals(Long.class) || type.equals(long.class)) {
         return stmt.columnLong(index);
      } else if (type.equals(Byte.class) || type.equals(byte.class) ) {
         return (byte)stmt.columnInt(index);
      } else if ( type.equals(Boolean.class) || type.equals(boolean.class) ) {
         return stmt.columnInt(index) != 0;
      } else if (type.equals(Double.class) || type.equals(double.class)) {
         return stmt.columnDouble(index);
      } else if (type.equals(float.class) || type.equals(Float.class)) {
         return (float)stmt.columnDouble(index);
      } else if (type.equals(Serializable.class)) {
         return stmt.columnBlob(index);
      }
   } catch (SQLiteException e) {
      log.error("sql bind invoker could not invoke:" , e);
   }

   return null;
}
 
Example #4
Source File: ProductLoaderForPairing.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Nullable
public static ProductCacheInfo saveOrClear(SubsystemContext<?> context, Optional<ProductCatalogEntry> product) {
	if(product !=null && product.isPresent()) {
		ProductCatalogEntry cur = product.get();
		ProductCacheInfo info = new ProductCacheInfo();
		info.pairingIdleTimeoutMs = cur.getPairingIdleTimeoutMs();
		info.pairingTimeoutMs = cur.getPairingTimeoutMs();	
		//Save it only if at least one value is not null to avoid saving ProductCacheInfo as Variable
		if(info.pairingIdleTimeoutMs != null || info.pairingTimeoutMs != null) {
			context.setVariable(VAR_PRODUCT_INFO, info);
			return info;
		}
	}
	context.setVariable(VAR_PRODUCT_INFO, null);
	return null;
}
 
Example #5
Source File: AlarmEvents.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static Event arm(Address addr, @Nullable Address actor, @NonNull MessageBody armRequest) {
   String armModeRaw = HubAlarmCapability.ArmRequest.getMode(armRequest);
   AlarmEvents.Mode armMode = "PARTIAL".equalsIgnoreCase(armModeRaw) ? AlarmEvents.Mode.PARTIAL : AlarmEvents.Mode.ON;

   Boolean bypassRaw = HubAlarmCapability.ArmRequest.getBypassed(armRequest);
   boolean bypass = bypassRaw == null ? false : bypassRaw.booleanValue();

   Integer entranceDelayRaw = HubAlarmCapability.ArmRequest.getEntranceDelaySecs(armRequest);
   int entranceDelay = entranceDelayRaw == null ? 30 : entranceDelayRaw.intValue();

   Integer exitDelayRaw = HubAlarmCapability.ArmRequest.getExitDelaySecs(armRequest);
   int exitDelay = exitDelayRaw == null ? 30 : exitDelayRaw.intValue();

   Integer alarmSensitivityRaw = HubAlarmCapability.ArmRequest.getAlarmSensitivityDeviceCount(armRequest);
   int alarmSensitivity = alarmSensitivityRaw == null ? 1 : alarmSensitivityRaw.intValue();

   Boolean silentRaw = HubAlarmCapability.ArmRequest.getSilent(armRequest);
   boolean silent = silentRaw == null ? false : silentRaw.booleanValue();

   Boolean soundsRaw = HubAlarmCapability.ArmRequest.getSoundsEnabled(armRequest);
   boolean sounds = soundsRaw == null ? false : soundsRaw.booleanValue();

   Collection<String> activeRaw = HubAlarmCapability.ArmRequest.getActiveDevices(armRequest);
   Set<String> active = activeRaw == null ? ImmutableSet.of() : ImmutableSet.copyOf(activeRaw);

   return new ArmEvent(addr, actor, armMode, bypass, entranceDelay, exitDelay, alarmSensitivity, silent, sounds, active);
}
 
Example #6
Source File: HistoryTable.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public BoundStatement listByIdBefore(
      CompositeId<UUID, Integer> id,
      @Nullable UUID before
) {
   if(before == null) {
      return listById(id);
   }
   return listByIdBefore.bind(id.getPrimaryId(), id.getSecondaryId(), before);
}
 
Example #7
Source File: RtspInterleavedHandler.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public void userEventTriggered(@Nullable ChannelHandlerContext ctx, @Nullable Object evt) throws Exception {
   if (evt instanceof IrisRtspSdp) {
      IrisRtspSdp sdp = (IrisRtspSdp)evt;
      log.trace("interleaved sdp: {}", sdp);
   }

   ctx.fireUserEventTriggered(evt);
}
 
Example #8
Source File: ComparableComparator.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(@Nullable T o1, @Nullable T o2) {
   if (o1 == o2) return 0;
   if (o1 == null) return -1;
   if (o2 == null) return 1;

   return o1.compareTo(o2);
}
 
Example #9
Source File: ConversionService.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Nullable
@SuppressWarnings("unchecked")
public static <T> String from(@Nullable T value) {
   if (value == null) {
      return null;
   }

   Class<T> clazz = (Class<T>)value.getClass();
   return lookup(clazz).from(value);
}
 
Example #10
Source File: TestDeviceServiceHandler_DeviceRemoved.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
protected void expectFindDeviceAndReturn(@Nullable String state) {
   if(state == null) {
      EasyMock.expect(deviceDao.findByProtocolAddress(device.getProtocolAddress())).andReturn(null);
   }
   else {
      device.setState(state);
      EasyMock.expect(deviceDao.findByProtocolAddress(device.getProtocolAddress())).andReturn(device);
   }
}
 
Example #11
Source File: SceneActionBuilder.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Nullable
public Action buildResilient() {
   Preconditions.checkNotNull(placeId, "Must specify placeId");
   Preconditions.checkNotNull(template, "Must specify a sceneTemplate");
   Preconditions.checkNotNull(name, "Must specify a name for the scene");
   Preconditions.checkNotNull(context, "Must specify the context");
   
   boolean isPremiumPlace = context.isPremium();
   ActionList.Builder builder = new ActionList.Builder();
   if(actions != null) {
      for(com.iris.messages.type.Action action: actions) {
         try {
            if(!Boolean.TRUE.equals(action.getPremium()) || isPremiumPlace) {
         	   addAction(action, template, builder);
            }else{
         	   context.logger().debug("Scene action [{}] for scene [{}] is skipped because place [{}] requires PREMIUM service level", action.getName(), template.getName(), context.getPlaceId());
            }
         }
         catch(Exception e) {
            context.logger().warn("Unable to create action for template [{}]", template, e);
         }
      }
   }
   if(notification) {
      addNotification(builder);
   }
   if(builder.isEmpty()) {
      return null;
   }
   return builder.build();
}
 
Example #12
Source File: PlatformBusClient.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public PlatformBusClient(
      @NonNull PlatformMessageBus bus,
      @NonNull Executor executor,
      long defaultTimeoutMs,
      @Nullable Set<AddressMatcher> matchers
) {
   Preconditions.checkNotNull(bus);
   Preconditions.checkNotNull(executor);
   this.bus = bus;
   this.executor = executor;
   this.defaultTimeoutMs = defaultTimeoutMs;
   if(matchers != null) {
      bus.addMessageListener(matchers, this::queue);
   }
}
 
Example #13
Source File: Db.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Boolean execute(SQLiteConnection conn) throws Exception {
   SQLiteBackup backup = conn.initializeBackup(destination);
   try {
      backup.backupStep(-1);
   } finally {
      backup.dispose();
   }

   return backup.isFinished();
}
 
Example #14
Source File: DoorsNLocksSubsystem.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private Map<String, String> notificationParams(Model m, @Nullable Map<String, String> additionalParams) {
   if(additionalParams == null) {
      additionalParams = ImmutableMap.of();
   }

   return ImmutableMap.<String, String>builder()
      .putAll(additionalParams)
      .put("deviceName", DeviceModel.getName(m, ""))
      .build();
}
 
Example #15
Source File: RxIris.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static Repeat repeat(long attempts, long delay, TimeUnit units, long duration, TimeUnit durationUnits, @Nullable AtomicBoolean alive) {
   return new RepeatBuilder()
      .attempts(attempts)
      .initial(delay, units)
      .delay(delay, units)
      .random((long)(0.10*TimeUnit.NANOSECONDS.convert(delay,units)), TimeUnit.NANOSECONDS)
      .factor(1.0)
      .duration(duration, durationUnits)
      .aliveOn(alive)
      .build();
}
 
Example #16
Source File: BaseAlarmIncidentService.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Nullable
protected AlarmIncident onPlatformCompleted(UUID placeId, UUID incidentId, Address cancelledBy) {
	AlarmIncident incident = incidentDao.findById(placeId, incidentId);
	if(incident == null) {
		logger.warn("Incident cancellation succeeded, but incident could not be found [{}]", incidentId);
		return null;
	}
	else if(incident.getHubAlertState() == null || incident.getHubAlertState() == AlertState.COMPLETE) {
		// fully complete
		return onCompleted(incident, cancelledBy);
	}
	else {
		logger.debug("Incident [{}] is platform complete, waiting on hub to fully clear", incidentId);
		MonitoringState monitoringState = null;
		switch(incident.getMonitoringState()) {
		case PENDING:
		case DISPATCHING:
			// cancelled before dispatch
			monitoringState = MonitoringState.CANCELLED;
		default:
			monitoringState = incident.getMonitoringState();
		}
		AlarmIncident updated =
			AlarmIncident
				.builder(incident)
				.withPlatformAlertState(AlertState.COMPLETE)
				.withMonitoringState(monitoringState)
				.withCancelledBy(cancelledBy)
				.build();
		save(incident, updated);
		return updated;
	}
}
 
Example #17
Source File: PairingState.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Nullable
private List<Map<String, Object>> getForm(ProductCatalogEntry product) {
	List<Map<String,Object>> inputs = new ArrayList<>();
	for(Step step: product.getPair()) {
		if(CollectionUtils.isEmpty(step.getInputs())) {
			continue;
		}
		
		for(Input input: step.getInputs()) {
			PairingInput pi = new PairingInput();
			pi.setLabel(input.getLabel());
			pi.setName(input.getName());
			switch(input.getType()) {
			case HIDDEN:
				pi.setType(PairingInput.TYPE_HIDDEN);
				break;
			case TEXT:
				pi.setType(PairingInput.TYPE_TEXT);
				break;
			default:
				throw new IllegalStateException("Invalid input type: " + input.getType());
			}
			pi.setValue(input.getValue());
			if(input.getMinlen() != null) {
				pi.setMinlen(input.getMinlen());
			}
			if(input.getMaxlen() != null) {
				pi.setMaxlen(input.getMaxlen());
			}
			pi.setRequired(Boolean.TRUE.equals(input.getRequired()));
			inputs.add(pi.toMap());
		}
	}
	
	return inputs;
}
 
Example #18
Source File: SessionController.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Nullable
private OculusSession getLastSession() {
   List<OculusSession> info = listRecentSessions();
   if(info == null || info.isEmpty()) {
      return null;
   }
   return info.get(0);
}
 
Example #19
Source File: TestVideoAddedAppender.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
protected PlatformMessage videoAdded(@Nullable Address actor) {
	Map<String, Object> attributes =
			ModelFixtures
				.buildRecordingAttributes((UUID) videoAddress.getId())
				.put(RecordingCapability.ATTR_PLACEID, placeId.toString())
				.put(RecordingCapability.ATTR_CAMERAID, cameraId.toString())
				.create();
	MessageBody added = MessageBody.buildMessage(Capability.EVENT_ADDED, attributes);
	return 
			PlatformMessage
				.buildBroadcast(added, Address.fromString((String) attributes.get(Capability.ATTR_ADDRESS)))
				.withActor(actor)
				.withPlaceId(placeId)
				.create();
}
 
Example #20
Source File: AbstractHubDriver.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public @Nullable UUID verifyPinCode(byte[] ascii) {
   try {
      return verifyPinCode(new String(ascii, StandardCharsets.US_ASCII));
   } catch (Exception ex) {
      log.warn("could not decode pin code: ", ex);
      return null;
   }
}
 
Example #21
Source File: BackupService.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static List<Callable<Void>> getBackupTasks(final Db db) {
   List<Callable<Void>> tasks = new ArrayList<>(listeners.size());
   for (final BackupListener listener : listeners) {
      tasks.add(new Callable<Void>() {
         @Override
         @Nullable
         public Void call() {
            listener.hubBackup(db);
            return null;
         }
      });
   }

   return tasks;
}
 
Example #22
Source File: TestDeviceServiceHandler_DeviceRemoved.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
protected PlatformMessage createRemovedEvent(@Nullable String status) {
   MessageBody event =
         DeviceAdvancedCapability.RemovedDeviceEvent
            .builder()
            .withProtocol(device.getProtocol())
            .withProtocolId(device.getProtocolid())
            .withStatus(status)
            .build();
   PlatformMessage message =
         PlatformMessage
            .createBroadcast(event, Address.fromString(device.getProtocolAddress()));
   return message;
}
 
Example #23
Source File: IrisLayout.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public String doLayout(@Nullable ILoggingEvent event) {
   if (event == null) {
      return "";
   }

   for(Map.Entry<String, String> e: event.getMDCPropertyMap().entrySet()) {
      object.addProperty(e.getKey(), e.getValue());
   }

   object.addProperty("ts", event.getTimeStamp());
   object.addProperty("lvl", event.getLevel().toString());
   object.addProperty("thd", event.getThreadName());
   object.addProperty("log", event.getLoggerName());
   object.addProperty("msg", event.getFormattedMessage());
   object.addProperty("svc", "agent");

   String hubId = IrisHal.getHubIdOrNull();
   if (hubId != null) {
      object.addProperty("hst", hubId);
   }

   String hubVersion = IrisHal.getOperatingSystemVersionOrNull();
   if (hubVersion != null) {
      object.addProperty("svr", hubVersion);
   }

   IThrowableProxy thrw = event.getThrowableProxy();
   if (thrw != null) {
      String stackTrace = converter.convert(event);
      object.addProperty("exc", stackTrace);
   } else {
      object.remove("exc");
   }

   return IrisAgentSotConverter.SOT + GSON.toJson(object);
}
 
Example #24
Source File: RxIris.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public void call(@Nullable T1 v1) {
   if (v1 == null) {
      throw new NullPointerException();
   }

   run(v1);
}
 
Example #25
Source File: RxIris.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static Retry retry(long attempts, long delay, TimeUnit units, long duration, TimeUnit durationUnits, @Nullable AtomicBoolean alive) {
   return new RetryBuilder()
      .attempts(attempts)
      .initial(delay, units)
      .delay(delay, units)
      .random((long)(0.10*TimeUnit.NANOSECONDS.convert(delay,units)), TimeUnit.NANOSECONDS)
      .factor(1.0)
      .duration(duration, durationUnits)
      .aliveOn(alive)
      .build();
}
 
Example #26
Source File: RxIris.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private static <T> Observable.Operator<T,T> logger(final LogLevel level, final Logger log, final String format) {
   return new Operator<T,T>() {
      @Override
      public rx.Subscriber<? super T> run(final rx.Subscriber<? super T> s) {
         return new rx.Subscriber<T>(s) {
            @Override
            public void onNext(@Nullable T value) {
               if (!s.isUnsubscribed()) {
                  dolog(level, log, format, value);
                  s.onNext(value);
               }
            }

            @Override
            public void onCompleted() {
               if (!s.isUnsubscribed()) {
                  s.onCompleted();
               }
            }

            @Override
            public void onError(@Nullable Throwable e) {
               if (!s.isUnsubscribed()) {
                  s.onError(e);
               }
            }
         };
      }
   };
}
 
Example #27
Source File: RecordingSessionFactory.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
protected abstract T create(
   VideoSessionRegistry registry,
   @Nullable ChannelHandlerContext ctx,
   VideoRecordingManager dao,
   RecordingEventPublisher eventPublisher,
   VideoStorageSession storage,
   double precapture,
   boolean stream
);
 
Example #28
Source File: SecurityAlarmTestCase.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
protected void armBypassed(String mode, Address source, @Nullable Address actor) {
	PlatformMessage message = 
   		PlatformMessage
   			.builder()
   			.from(source)
   			.to(model.getAddress())
   			.withActor(actor)
   			.withPayload(ArmRequest.builder().withMode(mode).build())
   			.create();
	alarm.armBypassed(context, message, mode);
}
 
Example #29
Source File: MetricFilters.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getTagProperty(JsonObject report, String name) {
   JsonObject tags = getTags(report);
   if (tags == null) {
      return null;
   }

   return getAsStringOrNull(tags, name);
}
 
Example #30
Source File: IrisPreconditions.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static int checkElementIndex(int index, int size, @Nullable String message, @Nullable Object... args) throws IllegalArgumentException {
   if (index >= size) {
      throw new IllegalArgumentException(format("Index [" + index + "] greater than [" + size + "]", message,args));
   }

   return index;
}