@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); // Create thread pool for processing requests. this.executor = Executors.newFixedThreadPool(getNumThreads()); }
@Override public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.initialize(monitor); // Set up metrics. this.processedEvents = createMeterMetric("processedEvents"); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.stop(monitor); if (executor != null) { executor.shutdown(); try { executor.awaitTermination(2, TimeUnit.SECONDS); } catch (InterruptedException e) { return; } } }
@Override public Timer createTimerMetric(String name) { return getTenantEngine().getMicroservice().getMetricRegistry().timer(getTenentMetricPrefix() + name); }
@Override public void startNestedComponent(ILifecycleComponent component, ILifecycleProgressMonitor monitor, boolean require) throws SiteWhereException { if (component instanceof ITenantEngineLifecycleComponent) { ((ITenantEngineLifecycleComponent) component).setTenantEngine(getTenantEngine()); } super.startNestedComponent(component, monitor, require); }
@Override public void setTenantEngine(IMicroserviceTenantEngine tenantEngine) { super.setTenantEngine(tenantEngine); try { DirectSchedulerFactory.getInstance().createScheduler(tenantEngine.getTenant().getToken(), INSTANCE_ID, new SimpleThreadPool(getNumProcessingThreads(), Thread.NORM_PRIORITY), new RAMJobStore()); } catch (SchedulerException e) { throw new RuntimeException("Unable to create Quartz scheduler for schedule manager.", e); } }
@Override public Meter createMeterMetric(String name) { return getTenantEngine().getMicroservice().getMetricRegistry().meter(getTenentMetricPrefix() + name); }
@Override public void initializeNestedComponent(ILifecycleComponent component, ILifecycleProgressMonitor monitor, boolean require) throws SiteWhereException { if (component instanceof ITenantEngineLifecycleComponent) { ((ITenantEngineLifecycleComponent) component).setTenantEngine(getTenantEngine()); } super.initializeNestedComponent(component, monitor, require); }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); if (getInboundProcessorsExecutor() != null) { getInboundProcessorsExecutor().shutdownNow(); } this.inboundProcessorsExecutor = Executors.newFixedThreadPool( getDecodedEventsConsumer().getInboundProcessingConfiguration().getProcessingThreadCount()); }
@Override public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.initialize(monitor); // Set up metrics. this.processedEvents = createMeterMetric("processedEvents"); this.failedEvents = createMeterMetric("failedEvents"); this.deviceLookupTimer = createTimerMetric("deviceLookup"); this.assignmentLookupTimer = createTimerMetric("assignmentLookup"); this.eventStorageTimer = createTimerMetric("eventStorage"); this.eventStorageStrategy = new UnaryEventStorageStrategy((IInboundProcessingTenantEngine) getTenantEngine(), this); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (getInboundProcessorsExecutor() != null) { getInboundProcessorsExecutor().shutdownNow(); } super.stop(monitor); }
/** * Get prefix added to metrics so they are unique. * * @return */ protected String getTenentMetricPrefix() { IMicroservice<?> microservice = getTenantEngine().getMicroservice(); ITenant tenant = getTenantEngine().getTenant(); String instanceId = microservice.getInstanceSettings().getInstanceId(); String identifier = microservice.getIdentifier().getPath(); String tenantToken = tenant.getToken(); return instanceId + "." + identifier + "." + tenantToken + "."; }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); // Start device event decoder. startNestedComponent(getDeviceEventDecoder(), monitor, true); // Start device event deduplicator if provided. if (getDeviceEventDeduplicator() != null) { startNestedComponent(getDeviceEventDeduplicator(), monitor, true); } // Start event receivers. for (IInboundEventReceiver<T> receiver : getInboundEventReceivers()) { startNestedComponent(receiver, monitor, true); } }
@Override public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.initialize(monitor); if (getScriptId() == null) { throw new SiteWhereException("Script id was not initialized properly."); } this.scriptMetadata = ((IConfigurableMicroservice<?>) getMicroservice()).getScriptManagement() .getScriptMetadata(getMicroservice().getIdentifier(), getTenantEngine().getTenant().getId(), getScriptId()); if (getScriptMetadata() == null) { throw new SiteWhereException("Script '" + getScriptId() + "' was not found."); } getLogger().info(String.format("Groovy component will use version %s of script '%s'", getScriptMetadata().getActiveVersion(), getScriptMetadata().getName())); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.stop(monitor); // Stop all inbound event receivers. if (getInboundEventReceivers().size() > 0) { for (IInboundEventReceiver<T> receiver : getInboundEventReceivers()) { stopNestedComponent(receiver, monitor); } } // Stop device event decoder. stopNestedComponent(getDeviceEventDecoder(), monitor); // Stop device event deduplicator if present. if (getDeviceEventDeduplicator() != null) { stopNestedComponent(getDeviceEventDeduplicator(), monitor); } }
@Override public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); // Verify that contact points were specified. String[] contactPoints = getContactPoints().getValue().split(","); if (contactPoints.length == 0) { throw new SiteWhereException("No contact points specified for Cassandra cluster."); } Cluster.Builder builder = Cluster.builder(); for (String contactPoint : contactPoints) { builder.addContactPoint(contactPoint.trim()); } PoolingOptions pooling = new PoolingOptions(); pooling.setMaxRequestsPerConnection(HostDistance.LOCAL, 32768); pooling.setMaxRequestsPerConnection(HostDistance.REMOTE, 32768); pooling.setMaxQueueSize(32768); builder.withPoolingOptions(pooling); this.cluster = builder.build(); this.session = getCluster().connect(); }
@Override public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.initialize(monitor); if ((getInboundEventReceivers() == null) || (getInboundEventReceivers().size() == 0)) { throw new SiteWhereException("No inbound event receivers registered for event source."); } if (getDeviceEventDecoder() == null) { throw new SiteWhereException("No device event decoder assigned."); } // Set up metrics. this.decodedEvents = createMeterMetric(getMetricPrefix() + "decodedEvents"); this.decodeFailures = createMeterMetric(getMetricPrefix() + "decodeFailures"); this.duplicates = createMeterMetric(getMetricPrefix() + "duplicates"); // Initialize device event decoder. initializeNestedComponent(getDeviceEventDecoder(), monitor, true); // Initialize device event deduplicator if provided. if (getDeviceEventDeduplicator() != null) { initializeNestedComponent(getDeviceEventDeduplicator(), monitor, true); } // Initialize event receivers. for (IInboundEventReceiver<T> receiver : getInboundEventReceivers()) { receiver.setEventSource(this); initializeNestedComponent(receiver, monitor, true); } }
@Override public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); String connectionUrl = "http://" + getHostname().getValue() + ":" + getConfiguration().getPort(); this.influx = InfluxDBFactory.connect(connectionUrl, getConfiguration().getUsername(), getConfiguration().getPassword()); influx.createDatabase(getDatabase().getValue()); if (getConfiguration().isEnableBatch()) { influx.enableBatch(getConfiguration().getBatchChunkSize(), getConfiguration().getBatchIntervalMs(), TimeUnit.MILLISECONDS); } influx.setLogLevel(convertLogLevel(getConfiguration().getLogLevel())); }