@Override public void run() { logger.info(TAG, "Starting upload"); // Send real time event if (storages == null) { sendRealTimeEvent(event); return; } // If the next (normal periodic) scheduled drain is starting and we have a back-off retry // scheduled future set, cancel it. if (this.period == 1 && future != null) { logger.info(TAG, "Canceling future sender"); future.cancel(false); } // Send events with normal persistence if (!running.compareAndSet(false, true)) { logger.info(TAG, "Skipping send, event sending is already in progress on different thread."); return; } send(); running.set(false); }
public void init(YMP owner) throws Exception { if (!__inited) { // _LOG.info("Initializing ymate-platform-log-" + VERSION); // __owner = owner; __moduleCfg = new DefaultModuleCfg(__owner); // 设置全局变量,便于配置文件内引用 System.getProperties().put("LOG_OUT_DIR", __moduleCfg.getOutputDir().getPath()); // if (__moduleCfg.getLoggerClass() != null) { __currentLogger = ClassUtils.impl(__moduleCfg.getLoggerClass(), ILogger.class); } if (__currentLogger == null) { __currentLogger = new DefaultLogger(); } __LOGGER_CACHE.put(__moduleCfg.getLoggerName(), __currentLogger); // __currentLogger.init(this, __moduleCfg.getLoggerName()); __currentLogger.console(__moduleCfg.allowOutputConsole()); // __inited = true; // 注册日志记录器事件 __owner.getEvents().registerEvent(LogEvent.class); } }
protected ConnectionFigure createConnection() { try { Class cLayer = Class.forName(objType); LayerConnection lc = (LayerConnection) cLayer.newInstance(); lc.setParams(params); // Each component is provided with a pointer to the parent NeuralNet object NeuralNetDrawing nnd = (NeuralNetDrawing) view.drawing(); lc.setParam("NeuralNet", nnd.getNeuralNet()); return lc; } catch (ClassNotFoundException cnfe) { log.warn( "ClassNotFoundException exception thrown while ConnectionFigure. Message is : " + cnfe.getMessage(), cnfe); } catch (InstantiationException ie) { log.warn( "InstantiationException exception thrown while ConnectionFigure. Message is : " + ie.getMessage(), ie); } catch (IllegalAccessException iae) { log.warn( "IllegalAccessException exception thrown while ConnectionFigure. Message is : " + iae.getMessage(), iae); } return null; }
public void destroy() throws Exception { if (__inited) { __inited = false; // for (ILogger _logger : __LOGGER_CACHE.values()) { _logger.destroy(); } __currentLogger = null; __moduleCfg = null; __owner = null; } }
private static void addDefaultProperties(ILogger logger) { logger.addProperty("Trace Created", new Date().toString()); try { String hostname = InetAddress.getLocalHost().getHostName(); logger.addProperty("Hostname", hostname); } catch (UnknownHostException uhe) { } /* * Unfortunately, the command line arguments to the Java application is * not available here Properties props = System.getProperties(); * Enumeration<?> e = props.propertyNames(); while * (e.hasMoreElements()) { String key = (String) e.nextElement(); * System.out.println(key + " " + props.getProperty(key)); } */ }
/** * 开始下载任务 * * @param downloadId * @param callback */ public void startTask(int downloadId, FileDownloaderCallback callback) { FileDownloaderModel model = getFileDownloaderModelById(downloadId); if (model != null) { BridgeListener bridgeListener = mListenerManager.getBridgeListener(downloadId); bridgeListener.addDownloadListener(callback); if (mDownloadingList.size() >= mConfiguration.getMaxDownloadingCount()) { // 下载中队列已满 if (!mWaitQueue.contains(model)) { mWaitQueue.offer(model); } bridgeListener.wait(downloadId); } else { mDownloadingList.add(model); final BaseDownloadTask task = FileDownloader.getImpl() .create(model.getUrl()) .setPath(model.getPath()) .setCallbackProgressTimes(100) .setAutoRetryTimes(mAutoRetryTimes) .setListener(bridgeListener); for (int i = 0; i < mHeaders.size(); i++) { task.addHeader(mHeaders.name(i), mHeaders.value(i)); } bridgeListener.setDownloadTask(task); task.start(); } } else { ILogger.e("Task does not exist!"); } }
public final Matrix44D getMatrix() { if (_modelview != null) { for (int i = 0; i < _matricesSize; i++) { final Matrix44D m = _providers[i].getMatrix(); if (m == null) { ILogger.instance().logError("Modelview multiplication failure"); } if (_matrices[i] != m) { // If one matrix differs we have to raplace all matrixes on Holders and recalculate // modelview _modelview._release(); // NEW MODELVIEW NEEDED _modelview = null; pullMatrixes(); break; } } } if (_modelview == null) { _modelview = new Matrix44D(_matrices[0]); for (int i = 1; i < _matricesSize; i++) { final Matrix44D m2 = _matrices[i]; Matrix44D m3 = _modelview.createMultiplication(m2); _modelview._release(); _modelview = m3; } } return _modelview; }
private void logInputParams() { if (!isInputChanged) { return; } logger.log(editingFinishedLogMessage()); isInputChanged = false; }
@Override public void onStartFailure(int errorCode) { super.onStartFailure(errorCode); if (mLogger != null) { mLogger.log("Advertising failed error code = " + errorCode); } }
@Override public void onStartSuccess(AdvertiseSettings settingsInEffect) { super.onStartSuccess(settingsInEffect); if (mLogger != null) { mLogger.log("Advertising started successfully"); } }
public void convert() { logger.log(convertLogMessage()); if (!parseInput()) { return; } double input = Double.parseDouble(inputValue); double output; try { output = LengthConverter.convertFromTo(inputMeasure, outputMeasure, input); result = String.valueOf(output); logger.log("Result: " + result + ";"); } catch (IllegalArgumentException e) { result = "result is too huge"; logger.log("Result is too huge;"); } }
/** * 删除一个任务 * * @param downloadId */ public void deleteTask(int downloadId) { if (mDbController.deleteTask(downloadId)) { FileDownloaderModel model = getFileDownloaderModelById(downloadId); if (model != null) { // 删除文件 new File(model.getPath()).delete(); } pauseTask(downloadId); removeDownloadingTask(downloadId); removeWaitQueueTask(downloadId); try { mAllTasks.remove(downloadId); } catch (Exception e) { ILogger.e(e); } } else { ILogger.e("delete failure"); } }
public ILogger getLogger(String loggerName) throws Exception { ILogger _logger = __LOGGER_CACHE.get(loggerName); if (_logger == null) { _logger = __currentLogger.getLogger(loggerName); if (_logger != null) { __LOGGER_CACHE.put(loggerName, _logger); } } return _logger; }
/** * 将一个等待中的任务从下等待队列中移除 * * @param downloadId */ protected synchronized void removeWaitQueueTask(int downloadId) { Iterator<FileDownloaderModel> iterator = mWaitQueue.iterator(); while (iterator.hasNext()) { FileDownloaderModel model = iterator.next(); if (model != null && model.getId() == downloadId) { try { iterator.remove(); } catch (Exception e) { ILogger.e(e); } return; } } }
private boolean sendBatch(String batchedEvents, IStorage storage) { // This is "" if we upload an empty file which we should just skip if (batchedEvents.equals("")) { removedStorages.add(storage); return true; } byte[] compressedBatchedEvents = compressor.compress(batchedEvents); // Write event string try { if (compressedBatchedEvents != null) { sender.sendEvent(compressedBatchedEvents, true); } else { sender.sendEvent(batchedEvents); } } catch (IOException e) { logger.error(TAG, "Cannot send event: " + e.getMessage()); int newPeriod = period * 2; if (newPeriod > SettingsStore.getCllSettingsAsInt(SettingsStore.Settings.MAXRETRYPERIOD)) { // The next scheduled drain is coming soon (~2.5 min so going higher exponentially won't // help) return false; } // If we don't remove these then on next call the drain method will end up creating a new // empty file by this name. storages.removeAll(removedStorages); EventQueueWriter r = new EventQueueWriter( endpoint, storages, clientTelemetry, cllEvents, logger, executorService, newPeriod); r.setSender(sender); future = executorService.schedule(r, newPeriod, TimeUnit.SECONDS); return false; // If we run into an error sending events we just return. This ensures we don't // lose events } return true; }
/** Sends a real time event by itself */ protected void sendRealTimeEvent(SerializedEvent singleEvent) { // Check to see if this single serialized event is greater than MAX_BUFFER_SIZE, if it is we // drop it. if (singleEvent.getSerializedData().length() > SettingsStore.getCllSettingsAsInt(SettingsStore.Settings.MAXEVENTSIZEINBYTES)) { return; } try { sender.sendEvent(singleEvent.getSerializedData()); } catch (IOException e) { // Edge case for real time events that try to send but don't have network. // In this case we need to write to disk // Force Normal latency so we don't keep looping back to here handler.log(singleEvent); logger.error(TAG, "Cannot send event"); } for (ICllEvents event : cllEvents) { event.sendComplete(); } }
/** Serializes, batches, and sends events */ protected void send() { // Ensure that the serialized event string is under MAXEVENTSIZEINBYTES. // If it is over MAXEVENTSIZEINBYTES then we should use 2 or more strings and send them for (IStorage storage : storages) { if (executorService.isShutdown()) { return; } List<String> events = storage.drain(); for (String event : events) { this.clientTelemetry.IncrementEventsQueuedForUpload(); // Check to see if this single serialized event is greater than MAX_BUFFER_SIZE, if it is we // drop it. if (event.length() > SettingsStore.getCllSettingsAsInt(SettingsStore.Settings.MAXEVENTSIZEINBYTES)) { // This could cause big problems if the host application decides to do a ton of processing // for each // dropped event. for (ICllEvents cllEvent : cllEvents) { cllEvent.eventDropped(event); } continue; } if (batcher.canAddToBatch(event)) { try { batcher.addEventToBatch(event); } catch (EventBatcher.BatchFullException e) { logger.error(TAG, "Could not add to batch"); } } else { // Full batch, send events String batchedEvents = batcher.getBatchedEvents(); try { batcher.addEventToBatch(event); } catch (EventBatcher.BatchFullException e) { logger.error(TAG, "Could not add to batch"); } boolean sendResult = sendBatch(batchedEvents, storage); if (sendResult == false) { storage.close(); return; } } } // Send remaining events that didn't fill a whole batch String batchedEvents = batcher.getBatchedEvents(); boolean sendResult = sendBatch(batchedEvents, storage); if (sendResult == false) { storage.close(); return; } storage.discard(); } logger.info(TAG, "Sent " + clientTelemetry.snapshot.getEventsQueuedForUpload() + " events."); for (ICllEvents event : cllEvents) { event.sendComplete(); } }
public List<String> getLog() { return logger.getLog(); }
/** * startAdvertising will open a Gatt server, add our chat services to it and start advertisement * with default settings. Advertising won't start if bluetooth is disabled or device doesn't * support the Peripheral mode. */ public void startAdvertising() { if (mBluetoothManager.getAdapter().isEnabled()) { if (mBluetoothManager.getAdapter().isMultipleAdvertisementSupported()) { mGattserver = mBluetoothManager.openGattServer( mContext, new BluetoothGattServerCallback() { @Override public void onConnectionStateChange( BluetoothDevice device, int status, int newState) { super.onConnectionStateChange(device, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED) { if (mLogger != null) { mLogger.log("Client connected: " + device.getAddress()); } mConnectedDevice = device; } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { if (mLogger != null) { mLogger.log("Client disconnected: " + device.getAddress()); } mConnectedDevice = null; } } @Override public void onCharacteristicReadRequest( BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic) { super.onCharacteristicReadRequest(device, requestId, offset, characteristic); if (mLogger != null) { mLogger.log("onCharacteristicReadRequest"); } } @Override public void onServiceAdded(int status, BluetoothGattService service) { super.onServiceAdded(status, service); BleAdvertiser.this.onServiceAdded(); } @Override public void onNotificationSent(BluetoothDevice device, int status) { super.onNotificationSent(device, status); if (mLogger != null) { mLogger.log("onNotificationSent"); } } @Override public void onCharacteristicWriteRequest( BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) { super.onCharacteristicWriteRequest( device, requestId, characteristic, preparedWrite, responseNeeded, offset, value); if (characteristic .getUuid() .equals(UUID.fromString(Constants.CHAT_CHARACTERISTIC_UUID))) { String msg = ""; if (value != null) { msg = new String(value); } mLogger.log("onCharacteristicWriteRequest: " + msg); } } }); mGattserver.addService(ServiceFactory.generateService()); } else { mLogger.log("Central mode not supported by the device!"); } } else { mLogger.log("Bluetooth is disabled!"); } }
public void setOutputMeasure(final Measure outputMeasure) { if (this.outputMeasure != outputMeasure) { logger.log(LogMessages.OUTPUT_MEASURE_WAS_CHANGED + outputMeasure.toString()); this.outputMeasure = outputMeasure; } }
public void setInputMeasure(final Measure inputMeasure) { if (this.inputMeasure != inputMeasure) { logger.log(LogMessages.INPUT_MEASURE_WAS_CHANGED + inputMeasure.toString()); this.inputMeasure = inputMeasure; } }