@Override protected void doStore(String id, T value) throws ObjectStoreException { if (id == null) { throw new ObjectStoreException(CoreMessages.objectIsNull("id")); } // this block is unfortunately necessary to counter a possible race condition // between multiple nonatomic calls to containsObject/storeObject StoredObject<T> obj = new StoredObject<>(id, value); synchronized (store) { if (store.values().contains(obj)) { throw new ObjectAlreadyExistsException(); } boolean written = false; while (!written) { Long key = Long.valueOf(System.nanoTime()); written = (store.put(key, obj) == null); } } }
} catch (ObjectStoreException e) { LOGGER.error(format("Flow at source '%s' could not track item '%s' as being processed. %s", flowName, id, e.getMessage()), e); return false;
@Override protected void doStore(String key, String value) throws ObjectStoreException { boolean wasAdded; if (key == null) { throw new ObjectStoreException(); } synchronized (this) // map is shared { wasAdded = map.containsKey(key); map.put(key, value); } barrier.countDown(); try { barrier.await(); } catch (Exception e) { synchronized (errorHappenedInChildThreads) { errorHappenedInChildThreads = true; } } if (wasAdded) { throw new ObjectAlreadyExistsException(); } }
private Serializable getCurrentWatermark() { try { if (watermarkObjectStore.contains(WATERMARK_OS_KEY)) { return watermarkObjectStore.retrieve(WATERMARK_OS_KEY); } else { return null; } } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to fetch watermark for Message source at location '%s'. %s", flowName, e.getMessage())), e); } }
private PersistentObjectStorePartition<T> getPartitionObjectStore(String partitionName) throws ObjectStoreException { if (!partitionsByName.containsKey(partitionName)) { throw new ObjectStoreException(CoreMessages.createStaticMessage("No partition named: " + partitionName)); } return partitionsByName.get(partitionName); }
private Serializable getUpdatedWatermark() { try { if (watermarkObjectStore.contains(UPDATED_WATERMARK_OS_KEY)) { return watermarkObjectStore.retrieve(UPDATED_WATERMARK_OS_KEY); } else { return null; } } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to fetch watermark for Message source at location '%s'. %s", flowName, e.getMessage())), e); } }
protected void serialize(File outputFile, StoreValue<T> storeValue) throws ObjectStoreException { try ( FileOutputStream fileOutputStream = new FileOutputStream(outputFile); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream); ObjectOutputStream objectOutputStream = new ObjectOutputStream(bufferedOutputStream)) { serializer.getInternalProtocol().serialize(storeValue, objectOutputStream); objectOutputStream.flush(); } catch (Exception se) { throw new ObjectStoreException(se); } }
private void updateRecentlyProcessedIds() throws ObjectStoreException { Lock osClearingLock = lockFactory.createLock(UPDATE_PROCESSED_LOCK); try { osClearingLock.lock(); List<String> strings = recentlyProcessedIds.allKeys(); idsOnUpdatedWatermark.clear(); strings.forEach(key -> { try { idsOnUpdatedWatermark.store(key, recentlyProcessedIds.retrieve(key)); } catch (ObjectStoreException e) { throw new MuleRuntimeException(createStaticMessage("An error occurred while updating the watermark Ids. Failed to update key '%s' in Watermark-IDs ObjectStore: %s", key, e.getMessage()), e); } }); recentlyProcessedIds.clear(); } finally { osClearingLock.unlock(); } }
protected File createOrRetrievePartitionDescriptorFile() throws ObjectStoreException { try { File partitionDescriptorFile = new File(partitionDirectory, PARTITION_DESCRIPTOR_FILE); if (partitionDescriptorFile.exists()) { this.partitionName = readPartitionFileName(partitionDirectory); return partitionDescriptorFile; } try (FileWriter fileWriter = new FileWriter(partitionDescriptorFile.getAbsolutePath(), false)) { fileWriter.write(partitionName); fileWriter.flush(); } return partitionDescriptorFile; } catch (Exception e) { throw new ObjectStoreException(e); } }
private void updateWatermark(Serializable value, Comparator comparator) { try { if (watermarkObjectStore.contains(WATERMARK_OS_KEY)) { Serializable currentValue = watermarkObjectStore.retrieve(WATERMARK_OS_KEY); if (compareWatermarks(currentValue, value, comparator) >= 0) { return; } watermarkObjectStore.remove(WATERMARK_OS_KEY); } updateRecentlyProcessedIds(); watermarkObjectStore.store(WATERMARK_OS_KEY, value); } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to update watermark value for message source at location '%s'. %s", flowName, e.getMessage())), e); } }
protected void createDirectory(File directory) throws ObjectStoreException { try { // To support concurrency we need to check if directory exists again // inside // synchronized method if (!directory.exists() && !directory.mkdirs()) { throw new MuleRuntimeException(failedToCreate("object store directory " + directory.getAbsolutePath())); } } catch (Exception e) { throw new ObjectStoreException(e); } }
buf.append("ObjectStoreException " + e + " caught:" + e.getMessage());
protected void validateKeyAndPartitionName(String key, String partitionName) throws ObjectStoreException { validateKey(key); if (partitionName == null || partitionName.trim().length() == 0) { throw new ObjectStoreException(createStaticMessage("partition name cannot be null or blank")); } }
@Override public void dispose() { super.dispose(); if (store instanceof ObjectStorePartition) { try { ((ObjectStorePartition) store).close(); } catch (ObjectStoreException e) { logger.warn("error closing object store: " + e.getMessage(), e); } } if (store != null) { disposeIfNeeded(store, logger); store = null; } }
protected void deleteStoreFile(File file) throws ObjectStoreException { if (file.exists()) { if (!file.delete()) { throw new ObjectStoreException(createStaticMessage("Deleting " + file.getAbsolutePath() + " failed")); } realKeyToUUIDIndex.removeValue(file.getName()); } else { throw new ObjectDoesNotExistException(); } }
lock.unlock(); LOGGER.error(format("Flow at source '%s' could not track item '%s' as being processed. %s", flowName, id, e.getMessage()), e); return false;
protected File createFileToStoreObject() throws ObjectStoreException { String filename = UUID.getUUID() + OBJECT_FILE_EXTENSION; try { return newFile(partitionDirectory, filename); } catch (MuleRuntimeException mre) { throw new ObjectStoreException(mre); } }
private Serializable getCurrentWatermark() { try { if (watermarkObjectStore.contains(WATERMARK_OS_KEY)) { return watermarkObjectStore.retrieve(WATERMARK_OS_KEY); } else { return null; } } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to fetch watermark for Message source at location '%s'. %s", flowName, e.getMessage())), e); } }
@Override protected void doStore(String id, T value) throws ObjectStoreException { if (id == null) { throw new ObjectStoreException(CoreMessages.objectIsNull("id")); } // this block is unfortunately necessary to counter a possible race condition // between multiple nonatomic calls to containsObject/storeObject StoredObject<T> obj = new StoredObject<>(id, value); synchronized (store) { if (store.values().contains(obj)) { throw new ObjectAlreadyExistsException(); } boolean written = false; while (!written) { Long key = Long.valueOf(System.nanoTime()); written = (store.put(key, obj) == null); } } }
private boolean accept(CoreEvent event) { if (event != null && isNewMessage(event)) { try { String id = getIdForEvent(event); String value = getValueForEvent(event); try { store.store(id, value); return true; } catch (ObjectAlreadyExistsException ex) { return false; } catch (ObjectStoreNotAvailableException e) { LOGGER.error("ObjectStore not available: " + e.getMessage()); return false; } catch (ObjectStoreException e) { LOGGER.warn("ObjectStore exception: " + e.getMessage()); return false; } } catch (MuleException e) { LOGGER.warn("Could not retrieve Id or Value for event: " + e.getMessage()); return false; } } else { return false; } }