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

com.dell.cpsd.hal.data.provider.client.amqp.AbstractAmqpHalDataProviderManager Maven / Gradle / Ivy

/**
 * Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved.
 * Dell EMC Confidential/Proprietary Information
 */

package com.dell.cpsd.hal.data.provider.client.amqp;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Date;

import com.dell.cpsd.common.logging.ILogger;

import com.dell.cpsd.hal.data.provider.client.log.HDPCLoggingManager;
import com.dell.cpsd.hal.data.provider.client.amqp.consumer.IAmqpHalDataProviderMessageHandler;
import com.dell.cpsd.hal.data.provider.client.amqp.consumer.IAmqpHalDataProviderConsumer;

import org.springframework.amqp.core.MessageProperties;

import com.dell.cpsd.hal.data.provider.api.DataProviderWorkAccepted;
import com.dell.cpsd.hal.data.provider.api.DataProviderWorkRejected;
import com.dell.cpsd.hal.data.provider.api.DataProviderWorkStarted;
import com.dell.cpsd.hal.data.provider.api.DataProviderWorkFailed;
import com.dell.cpsd.hal.data.provider.api.DataProviderWorkTimeout;
import com.dell.cpsd.hal.data.provider.api.DataProviderWorkProgress;
import com.dell.cpsd.hal.data.provider.api.DataProviderWorkCancelled;

import com.dell.cpsd.hal.data.provider.api.FailureReason;
import com.dell.cpsd.hal.data.provider.api.RejectionReason;
import com.dell.cpsd.hal.data.provider.api.TimeoutReason;

import com.dell.cpsd.hal.data.provider.client.handler.IHalDataProviderWorkHandler;

import com.dell.cpsd.hal.data.provider.client.IHalDataProviderWorkManager;

/**
 * This abstract class assists in managing HAL data provider workflows.
 *
 * 

* Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. * Dell EMC Confidential/Proprietary Information *

* * @since 1.0 */ public abstract class AbstractAmqpHalDataProviderManager implements IAmqpHalDataProviderMessageHandler, IHalDataProviderWorkManager { /* * The logger for this class. */ private static final ILogger LOGGER = HDPCLoggingManager.getLogger(AbstractAmqpHalDataProviderManager.class); /* * The data provider message consumer. */ private IAmqpHalDataProviderConsumer halDataProviderConsumer; /* * The request identifier to handler mapping. */ private Map requestHandlers = null; /** * AbstractAmqpHalDataProviderManager constructor. * * @param halDataProviderConsumer * The data provider message consumer. * * @since 1.0 */ public AbstractAmqpHalDataProviderManager(final IAmqpHalDataProviderConsumer halDataProviderConsumer) { super(); this.requestHandlers = new HashMap(); if (halDataProviderConsumer == null) { throw new IllegalArgumentException("The data provider consumer is null."); } this.halDataProviderConsumer = halDataProviderConsumer; this.halDataProviderConsumer.setMessageHandler(this); } /** * This returns the IAmqpHalDataProviderConsumer used by this manager. * * @return The message consumer used by this manager. * * @since 1.0 */ public IAmqpHalDataProviderConsumer getHalDataProviderConsumer() { return this.halDataProviderConsumer; } /** * {@inheritDoc} */ @Override public boolean registerHandler(final String requestId, final H handler) { if ((requestId == null) || (requestId.isEmpty())) { return false; } if (handler == null) { return false; } synchronized (this.requestHandlers) { this.requestHandlers.put(requestId, handler); } return true; } /** * {@inheritDoc} */ @Override public H unregisterHandler(final String requestId) { synchronized (this.requestHandlers) { return this.requestHandlers.remove(requestId); } } /** * {@inheritDoc} */ @Override public H lookupHandler(final String requestId) { synchronized (this.requestHandlers) { return this.requestHandlers.get(requestId); } } /** * {@inheritDoc} */ @Override public void handleDataProviderWorkAccepted(final DataProviderWorkAccepted message, final MessageProperties messageProperties) { final String requestId = message.getRequestId(); final H requestHandler = this.lookupHandler(requestId); if (requestHandler == null) { return; } final String trackingId = message.getTrackingId(); final Date timestamp = message.getTimestamp(); try { requestHandler.dataProviderWorkAccepted(timestamp, requestId, trackingId); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } } /** * {@inheritDoc} */ @Override public void handleDataProviderWorkRejected(final DataProviderWorkRejected message, final MessageProperties messageProperties) { final String requestId = message.getRequestId(); final H requestHandler = this.lookupHandler(requestId); if (requestHandler == null) { return; } final Date timestamp = message.getTimestamp(); final List rejectionReasons = message.getRejectionReasons(); try { requestHandler.dataProviderWorkRejected(timestamp, requestId, rejectionReasons); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } } /** * {@inheritDoc} */ @Override public void handleDataProviderWorkStarted(final DataProviderWorkStarted message, final MessageProperties messageProperties) { final String requestId = message.getRequestId(); final H requestHandler = this.lookupHandler(requestId); if (requestHandler == null) { return; } final String trackingId = message.getTrackingId(); final Date timestamp = message.getTimestamp(); try { requestHandler.dataProviderWorkStarted(timestamp, requestId, trackingId); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } } /** * {@inheritDoc} */ @Override public void handleDataProviderWorkProgress(final DataProviderWorkProgress message, final MessageProperties messageProperties) { final String requestId = message.getRequestId(); final H requestHandler = this.lookupHandler(requestId); if (requestHandler == null) { return; } final String trackingId = message.getTrackingId(); final Date timestamp = message.getTimestamp(); try { requestHandler.dataProviderWorkProgress(timestamp, requestId, trackingId); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } } /** * {@inheritDoc} */ @Override public void handleDataProviderWorkFailed(final DataProviderWorkFailed message, final MessageProperties messageProperties) { final String requestId = message.getRequestId(); final H requestHandler = this.lookupHandler(requestId); if (requestHandler == null) { return; } final String trackingId = message.getTrackingId(); final Date timestamp = message.getTimestamp(); final List failureReasons = message.getFailureReasons(); try { requestHandler.dataProviderWorkFailed(timestamp, requestId, trackingId, failureReasons); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } } /** * {@inheritDoc} */ @Override public void handleDataProviderWorkTimeout(final DataProviderWorkTimeout message, final MessageProperties messageProperties) { final String requestId = message.getRequestId(); final H requestHandler = this.lookupHandler(requestId); if (requestHandler == null) { return; } final String trackingId = message.getTrackingId(); final Date timestamp = message.getTimestamp(); final TimeoutReason timeoutReason = message.getTimeoutReason(); try { requestHandler.dataProviderWorkTimeout(timestamp, requestId, trackingId, timeoutReason); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } } /** * {@inheritDoc} */ @Override public void handleDataProviderWorkCancelled(final DataProviderWorkCancelled message, final MessageProperties messageProperties) { final String requestId = message.getRequestId(); final H requestHandler = this.lookupHandler(requestId); if (requestHandler == null) { return; } final String trackingId = message.getTrackingId(); final Date timestamp = message.getTimestamp(); try { requestHandler.dataProviderWorkCancelled(timestamp, requestId, trackingId); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy