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

nstream.adapter.common.egress.PublisherAgent Maven / Gradle / Ivy

There is a newer version: 4.15.23
Show newest version
// Copyright 2015-2024 Nstream, inc.
//
// Licensed under the Redis Source Available License 2.0 (RSALv2) Agreement;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://redis.com/legal/rsalv2-agreement/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package nstream.adapter.common.egress;

import nstream.adapter.common.AdapterSettings;
import nstream.adapter.common.NstreamAgent;
import nstream.adapter.common.schedule.DeferrableException;
import swim.structure.Value;

/**
 * An abstract Web Agent that can push its state to an external process.
 * Requirements specific to the external process will be handled by the
 * implementing subclasses.
 * The {@link PublisherAgent} class encapsulates the settings object required to
 * configure publication and provides methods to load these settings.
 * 

* Scheduling of asynchronous tasks can be achieved using the base * {@link NstreamAgent}. * * @param the settings used to configure publication * @param the type to be published externally */ public abstract class PublisherAgent extends NstreamAgent { protected S egressSettings; public PublisherAgent() { } /** * Get the settings agent property and load value as settings. * * @param propName agent property name of the settings * @see #loadSettings(Value) */ protected final void loadSettings(String propName) { loadSettings(getProp(propName)); } /** * Parse and set the settings {@link Value} from agent configuration. * * @param prop agent settings value to be loaded * @see #parseEgressSettings(Value) * @see #loadSettings(S) */ protected final void loadSettings(Value prop) { loadSettings(parseEgressSettings(prop)); } /** * Parse the agent settings {@link Value} and mold to a {@link S} * object. * * @param prop agent settings value to be parsed to {@link S} * @return settings object */ protected abstract S parseEgressSettings(Value prop); /** * Set the settings that have been loaded from agent configuration. * * @param egressSettings settings loaded from agent configuration */ protected void loadSettings(S egressSettings) { this.egressSettings = egressSettings; } /** * Publish a {@link Value} to an external process. * Will likely convert the {@link Value} object to {@link V} and * defer publishing to {@link PublisherAgent#publish(V)}. * * @param structure the state to be published * @throws DeferrableException an exception that will be handled without aborting publishing * @throws RuntimeException an exception that will abort publishing */ protected abstract void publish(Value structure) throws DeferrableException; /** * Publish a {@link V} to an external process. * * @param publishable the state to be published * @throws DeferrableException an exception that will be handled without aborting publishing * @throws RuntimeException an exception that will abort publishing */ protected abstract void publish(V publishable) throws DeferrableException; /** * Prepare the agent for publication. * Load settings object and schedule publishing as required. */ protected abstract void stagePublication(); }