/** * Invoke the custom exception handler (if present) * * @param ex * The exception that occurred. */ private static void _invokeCustomExceptionCallback (@Nonnull final Exception ex) { s_aExceptionCallbacks.forEach (x -> x.onException (ex)); }
public static final void onExecutionTimeExceeded (@Nonnull final String sMsg, @Nonnegative final long nExecutionMillis) { s_aExecutionTimeExceededHandlers.forEach (x -> x.onExecutionTimeExceeded (sMsg, nExecutionMillis)); }
protected final void internalTriggerEvent (@Nonnull final EMicroEvent eEventType, @Nonnull final IMicroEvent aEvent) { // Any event targets present? if (m_aEventTargets != null && m_aEventTargets.isNotEmpty ()) { // Get all event handler final CallbackList <IMicroEventTarget> aTargets = m_aEventTargets.get (eEventType); if (aTargets != null) aTargets.forEach (x -> x.handleEvent (aEvent)); } // Bubble to parent if (m_aParentNode != null) m_aParentNode.internalTriggerEvent (eEventType, aEvent); }
/** * Mark an item as "no longer deleted" without actually adding it to the map. * This method only triggers the update action but does not alter the item. * Must only be invoked inside a write-lock. * * @param aItem * The item that was marked as "no longer deleted" * @param bInvokeCallbacks * <code>true</code> to invoke callbacks, <code>false</code> to not do * so. * @since 9.2.1 */ @MustBeLocked (ELockType.WRITE) protected final void internalMarkItemUndeleted (@Nonnull final IMPLTYPE aItem, final boolean bInvokeCallbacks) { // Trigger save changes super.markAsChanged (aItem, EDAOActionType.UPDATE); if (bInvokeCallbacks) { // Invoke callbacks m_aCallbacks.forEach (aCB -> aCB.onMarkItemUndeleted (aItem)); } }
aCallbacks.forEach (IParallelRunningRequestCallback::onParallelRunningRequestsBelowLimit);
/** * Mark an item as "deleted" without actually deleting it from the map. This * method only triggers the update action but does not alter the item. Must * only be invoked inside a write-lock. * * @param aItem * The item that was marked as "deleted" * @param bInvokeCallbacks * <code>true</code> to invoke callbacks, <code>false</code> to not do * so. * @since 9.2.1 */ @MustBeLocked (ELockType.WRITE) protected final void internalMarkItemDeleted (@Nonnull final IMPLTYPE aItem, final boolean bInvokeCallbacks) { // Trigger save changes super.markAsChanged (aItem, EDAOActionType.UPDATE); if (bInvokeCallbacks) { // Invoke callbacks m_aCallbacks.forEach (aCB -> aCB.onMarkItemDeleted (aItem)); } }
@Nullable public final JAXBTYPE read (@Nonnull final IJAXBUnmarshaller <JAXBTYPE> aHandler) { ValueEnforcer.notNull (aHandler, "Handler"); try { final Unmarshaller aUnmarshaller = _createUnmarshaller (getClassLoader ()); customizeUnmarshaller (aUnmarshaller); return aHandler.doUnmarshal (aUnmarshaller, m_aType).getValue (); } catch (final JAXBException ex) { m_aReadExceptionCallbacks.forEach (x -> x.onException (ex)); } return null; }
@Nullable public JAXBTYPE read (@Nonnull final IJAXBUnmarshaller <JAXBTYPE> aHandler) { ValueEnforcer.notNull (aHandler, "Handler"); // as we don't have a node, we need to trust the implementation class final Schema aSchema = getSchema (); if (aSchema == null && isUseSchema ()) LOGGER.warn ("Don't know how to read JAXB document of type " + m_aImplClass.getName ()); JAXBTYPE ret = null; try { // Create unmarshaller final Unmarshaller aUnmarshaller = createUnmarshaller (); // Customize on demand if (m_aUnmarshallerCustomizer != null) m_aUnmarshallerCustomizer.accept (aUnmarshaller); // main unmarshalling final JAXBElement <JAXBTYPE> aElement = aHandler.doUnmarshal (aUnmarshaller, m_aImplClass); ret = aElement.getValue (); if (ret == null) throw new IllegalStateException ("Failed to read JAXB document of class " + m_aImplClass.getName () + " - without exception!"); } catch (final JAXBException ex) { exceptionCallbacks ().forEach (x -> x.onException (ex)); } return ret; }
/** * Add an item including invoking the callback. Must only be invoked inside a * write-lock. * * @param aNewItem * The item to be added. May not be <code>null</code>. * @param bInvokeCallbacks * <code>true</code> to invoke callbacks, <code>false</code> to not do * so. * @return The passed parameter as-is. Never <code>null</code>. * @throws IllegalArgumentException * If an item with the same ID is already contained * @since 9.2.1 */ @MustBeLocked (ELockType.WRITE) @Nonnull protected final IMPLTYPE internalCreateItem (@Nonnull final IMPLTYPE aNewItem, final boolean bInvokeCallbacks) { // Add to map _addItem (aNewItem, EDAOActionType.CREATE); // Trigger save changes super.markAsChanged (aNewItem, EDAOActionType.CREATE); if (bInvokeCallbacks) { // Invoke callbacks m_aCallbacks.forEach (aCB -> aCB.onCreateItem (aNewItem)); } return aNewItem; }
/** * Trigger the registered custom exception handlers for read errors. * * @param t * Thrown exception. Never <code>null</code>. * @param sErrorFilename * The filename tried to write to. Never <code>null</code>. * @param aDoc * The XML content that should be written. May be <code>null</code> if * the error occurred in XML creation. */ protected static void triggerExceptionHandlersWrite (@Nonnull final Throwable t, @Nonnull final String sErrorFilename, @Nullable final IMicroDocument aDoc) { // Check if a custom exception handler is present if (exceptionHandlersWrite ().isNotEmpty ()) { final IReadableResource aRes = new FileSystemResource (sErrorFilename); final String sXMLContent = aDoc == null ? "no XML document created" : MicroWriter.getNodeAsString (aDoc); exceptionHandlersWrite ().forEach (aCB -> aCB.onDAOWriteException (t, aRes, sXMLContent)); } }
/** * Trigger the registered custom exception handlers for read errors. * * @param t * Thrown exception. Never <code>null</code>. * @param sErrorFilename * The filename tried to write to. Never <code>null</code>. * @param aDoc * The XML content that should be written. May be <code>null</code> if * the error occurred in XML creation. */ protected static void triggerExceptionHandlersWrite (@Nonnull final Throwable t, @Nonnull final String sErrorFilename, @Nullable final IMicroDocument aDoc) { // Check if a custom exception handler is present if (exceptionHandlersWrite ().isNotEmpty ()) { final IReadableResource aRes = new FileSystemResource (sErrorFilename); final String sXMLContent = aDoc == null ? "no XML document created" : MicroWriter.getNodeAsString (aDoc); exceptionHandlersWrite ().forEach (aCB -> aCB.onDAOWriteException (t, aRes, sXMLContent)); } }
/** * Trigger the registered custom exception handlers for read errors. * * @param t * Thrown exception. Never <code>null</code>. * @param bIsInitialization * <code>true</code> if this happened during initialization of a new * file, <code>false</code> if it happened during regular reading. * @param aFile * The file that was read. May be <code>null</code> for in-memory DAOs. */ protected static void triggerExceptionHandlersRead (@Nonnull final Throwable t, final boolean bIsInitialization, @Nullable final File aFile) { // Custom exception handler for reading if (exceptionHandlersRead ().isNotEmpty ()) { final IReadableResource aRes = aFile == null ? null : new FileSystemResource (aFile); exceptionHandlersRead ().forEach (aCB -> aCB.onDAOReadException (t, bIsInitialization, aRes)); } }
/** * Trigger the registered custom exception handlers for read errors. * * @param t * Thrown exception. Never <code>null</code>. * @param bIsInitialization * <code>true</code> if this happened during initialization of a new * file, <code>false</code> if it happened during regular reading. * @param aFile * The file that was read. May be <code>null</code> for in-memory DAOs. */ protected static void triggerExceptionHandlersRead (@Nonnull final Throwable t, final boolean bIsInitialization, @Nullable final File aFile) { // Custom exception handler for reading if (exceptionHandlersRead ().isNotEmpty ()) { final IReadableResource aRes = aFile == null ? null : new FileSystemResource (aFile); exceptionHandlersRead ().forEach (aCB -> aCB.onDAOReadException (t, bIsInitialization, aRes)); } }
/** * Update an existing item including invoking the callback. Must only be * invoked inside a write-lock. * * @param aItem * The item to be updated. May not be <code>null</code>. * @param bInvokeCallbacks * <code>true</code> to invoke callbacks, <code>false</code> to not do * so. * @throws IllegalArgumentException * If no item with the same ID is already contained * @since 9.2.1 */ @MustBeLocked (ELockType.WRITE) protected final void internalUpdateItem (@Nonnull final IMPLTYPE aItem, final boolean bInvokeCallbacks) { // Add to map - ensure to overwrite any existing _addItem (aItem, EDAOActionType.UPDATE); // Trigger save changes super.markAsChanged (aItem, EDAOActionType.UPDATE); if (bInvokeCallbacks) { // Invoke callbacks m_aCallbacks.forEach (aCB -> aCB.onUpdateItem (aItem)); } }
@Nonnull public final ESuccess write (@Nonnull final JAXBTYPE aObject, @Nonnull final IJAXBMarshaller <JAXBTYPE> aMarshallerFunc) { ValueEnforcer.notNull (aObject, "Object"); ValueEnforcer.notNull (aMarshallerFunc, "MarshallerFunc"); try { final Marshaller aMarshaller = _createMarshaller (); customizeMarshaller (aMarshaller); final JAXBElement <JAXBTYPE> aJAXBElement = m_aJAXBElementWrapper.apply (aObject); aMarshallerFunc.doMarshal (aMarshaller, aJAXBElement); return ESuccess.SUCCESS; } catch (final JAXBException ex) { m_aWriteExceptionCallbacks.forEach (x -> x.onException (ex)); } return ESuccess.FAILURE; }
m_aCallbacks.forEach (aCB -> aCB.onDeleteItem (aDeletedItem));
@Nonnull public EChange deleteSMPBusinessCard (@Nullable final ISMPBusinessCard aSMPBusinessCard) { if (aSMPBusinessCard == null) return EChange.UNCHANGED; LOGGER.info ("deleteSMPBusinessCard (" + aSMPBusinessCard.getID () + ")"); m_aRWLock.writeLock ().lock (); try { final SMPBusinessCard aRealBusinessCard = internalDeleteItem (aSMPBusinessCard.getID ()); if (aRealBusinessCard == null) { AuditHelper.onAuditDeleteFailure (SMPBusinessCard.OT, "no-such-id", aSMPBusinessCard.getID ()); return EChange.UNCHANGED; } } finally { m_aRWLock.writeLock ().unlock (); } // Invoke generic callbacks m_aCBs.forEach (x -> x.onDeleteSMPBusinessCard (aSMPBusinessCard)); AuditHelper.onAuditDeleteSuccess (SMPBusinessCard.OT, aSMPBusinessCard.getID (), aSMPBusinessCard.getServiceGroupID (), Integer.valueOf (aSMPBusinessCard.getEntityCount ())); LOGGER.info ("deleteSMPBusinessCard successful"); return EChange.CHANGED; }
@Nonnull public EChange deleteSMPBusinessCard (@Nullable final ISMPBusinessCard aSMPBusinessCard) { if (aSMPBusinessCard == null) return EChange.UNCHANGED; LOGGER.info ("deleteSMPBusinessCard (" + aSMPBusinessCard.getID () + ")"); m_aRWLock.writeLock ().lock (); try { final SMPBusinessCard aRealBusinessCard = internalDeleteItem (aSMPBusinessCard.getID ()); if (aRealBusinessCard == null) { AuditHelper.onAuditDeleteFailure (SMPBusinessCard.OT, "no-such-id", aSMPBusinessCard.getID ()); return EChange.UNCHANGED; } } finally { m_aRWLock.writeLock ().unlock (); } // Invoke generic callbacks m_aCBs.forEach (x -> x.onDeleteSMPBusinessCard (aSMPBusinessCard)); AuditHelper.onAuditDeleteSuccess (SMPBusinessCard.OT, aSMPBusinessCard.getID (), aSMPBusinessCard.getServiceGroupID (), Integer.valueOf (aSMPBusinessCard.getEntityCount ())); LOGGER.info ("deleteSMPBusinessCard successful"); return EChange.CHANGED; }
m_aCBs.forEach (x -> x.onDeleteSMPBusinessCard (aSMPBusinessCard));
m_aCallbacks.forEach (x -> x.onSMPSettingsChanged (m_aSettings));