All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.base.javaTemplate.vsl Maven / Gradle / Ivy

There is a newer version: 9.3.47
Show newest version
## Velocity Template.
## Copyright (C) 2024 gregory higgins
/*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* Server Side License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program.  If not, see
*
.
*/
package ${package};

import com.fluxtion.runtime.StaticEventProcessor;
import com.fluxtion.runtime.lifecycle.BatchHandler;
import com.fluxtion.runtime.lifecycle.Lifecycle;
import com.fluxtion.runtime.EventProcessor;
import com.fluxtion.runtime.callback.InternalEventProcessor;
#if(${MODEL.imports})
    ${MODEL.imports}
#end
import java.util.IdentityHashMap;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;

/**
*
* generation time                 : ${build_time}
* eventProcessorGenerator version : ${generator_version_information}
* api version                     : ${api_version_information}
*
* Event classes supported: *
    ${MODEL.javaDocEventClassList} *
* @author Greg Higgins */ @SuppressWarnings({"unchecked", "rawtypes"}) public class ${className} implements EventProcessor<${className}>, ${MODEL.additionalInterfaces} StaticEventProcessor, InternalEventProcessor, BatchHandler, Lifecycle { //Node declarations ${MODEL.nodeDeclarations} private final ExportFunctionAuditEvent functionAudit = new ExportFunctionAuditEvent(); //Dirty flags private boolean initCalled = false; private boolean processing = false; private boolean buffering = false; private final IdentityHashMap dirtyFlagSupplierMap = new IdentityHashMap<>(${MODEL.dirtyFlagCount}); private final IdentityHashMap> dirtyFlagUpdateMap = new IdentityHashMap<>(${MODEL.dirtyFlagCount}); ${MODEL.dirtyFlagDeclarations} ${MODEL.forkDeclarations} //Filter constants ${MODEL.filterConstantDeclarations} //unknown event handler private Consumer unKnownEventHandler = (e) -> {}; public ${className} (Map contextMap) { if(context != null) { context.replaceMappings(contextMap); } ${MODEL.nodeMemberAssignments} if(subscriptionManager != null){ subscriptionManager.setSubscribingEventProcessor(this); } if(context != null) { context.setEventProcessorCallback(this); } } public ${className} () { this(null); } ${MODEL.dispatchOnlyNodeMemberAssignments} @Override public void init() { initCalled = true; auditEvent(Lifecycle.LifecycleEvent.Init); //initialise dirty lookup map isDirty("test"); ${MODEL.initialiseMethods} afterEvent(); } @Override public void start() { if(!initCalled){ throw new RuntimeException("init() must be called before start()"); } processing = true; auditEvent(Lifecycle.LifecycleEvent.Start); ${MODEL.startMethods} afterEvent(); callbackDispatcher.dispatchQueuedCallbacks(); processing = false; } @Override public void stop() { if(!initCalled){ throw new RuntimeException("init() must be called before stop()"); } processing = true; auditEvent(Lifecycle.LifecycleEvent.Stop); ${MODEL.stopMethods} afterEvent(); callbackDispatcher.dispatchQueuedCallbacks(); processing = false; } @Override public void tearDown() { initCalled = false; auditEvent(Lifecycle.LifecycleEvent.TearDown); ${MODEL.tearDownMethods} afterEvent(); } @Override public void setContextParameterMap(Map newContextMapping){ context.replaceMappings(newContextMapping); } @Override public void addContextParameter(Object key, Object value) { context.addMapping(key, value); } //EVENT DISPATCH - START @Override public void onEvent(Object event) { if(buffering){ triggerCalculation(); } if(processing){ callbackDispatcher.processReentrantEvent(event); }else{ processing = true; onEventInternal(event); callbackDispatcher.dispatchQueuedCallbacks(); processing = false; } } @Override public void onEventInternal(Object event) { ${MODEL.eventDispatch} } ${MODEL.eventHandlers} private void beforeServiceCall(String functionDescription){ functionAudit.setFunctionDescription(functionDescription); auditEvent(functionAudit); if (buffering) { triggerCalculation(); } processing = true; } private void afterServiceCall(){ afterEvent(); callbackDispatcher.dispatchQueuedCallbacks(); processing = false; } private void afterEvent() { ${MODEL.eventEndMethods} ${MODEL.resetDirtyFlags} ${MODEL.resetForkTasks} } @Override public void batchPause() { auditEvent(Lifecycle.LifecycleEvent.BatchPause); processing = true; ${MODEL.batchPauseMethods} afterEvent(); callbackDispatcher.dispatchQueuedCallbacks(); processing = false; } @Override public void batchEnd() { auditEvent(Lifecycle.LifecycleEvent.BatchEnd); processing = true; ${MODEL.batchEndMethods} afterEvent(); callbackDispatcher.dispatchQueuedCallbacks(); processing = false; } @Override public boolean isDirty(Object node) { return dirtySupplier(node).getAsBoolean(); } @Override public BooleanSupplier dirtySupplier(Object node) { if(dirtyFlagSupplierMap.isEmpty()){ ${MODEL.dirtyFlagLookup} } return dirtyFlagSupplierMap.getOrDefault(node, StaticEventProcessor.ALWAYS_FALSE); } @Override public void setDirty(Object node, boolean dirtyFlag) { if(dirtyFlagUpdateMap.isEmpty()){ ${MODEL.dirtyFlagUpdate} } dirtyFlagUpdateMap.get(node).accept(dirtyFlag); } ${MODEL.guardCheckMethods} @Override public T getNodeById(String id) throws NoSuchFieldException { return nodeNameLookup.getInstanceById(id); } @Override public A getAuditorById(String id) throws NoSuchFieldException, IllegalAccessException { return (A) this.getClass().getField(id).get(this); } @Override public void addEventFeed(EventFeed eventProcessorFeed) { subscriptionManager.addEventProcessorFeed(eventProcessorFeed); } @Override public void removeEventFeed(EventFeed eventProcessorFeed) { subscriptionManager.removeEventProcessorFeed(eventProcessorFeed); } @Override public ${className} newInstance(){ return new ${className}(); } @Override public ${className} newInstance(Map contextMap){ return new ${className}(); } ${MODEL.assignNodeField} @Override public String getLastAuditLogRecord() { try { EventLogManager eventLogManager = (EventLogManager) this.getClass().getField(EventLogManager.NODE_NAME).get(this); return eventLogManager.lastRecordAsString(); } catch (Throwable e) { return ""; } } public void unKnownEventHandler(Object object) { unKnownEventHandler.accept(object); } @Override public void setUnKnownEventHandler(Consumer consumer){ unKnownEventHandler = consumer; } @Override public SubscriptionManager getSubscriptionManager() { return subscriptionManager; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy