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

org.eclipse.serializer.communication.binarydynamic.ComHandlerRegistry Maven / Gradle / Ivy

package org.eclipse.serializer.communication.binarydynamic;

/*-
 * #%L
 * Eclipse Serializer Communication Binary
 * %%
 * Copyright (C) 2023 MicroStream Software
 * %%
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 * 
 * SPDX-License-Identifier: EPL-2.0
 * #L%
 */

import org.eclipse.serializer.collections.MiniMap;
import org.eclipse.serializer.util.logging.Logging;
import org.slf4j.Logger;

public interface ComHandlerRegistry
{
	public  boolean registerSendHandler    (final Class type, final ComHandlerSend handler);
	public  boolean registerReceiveHandler (final Class type, final ComHandlerReceive handler);
	
	public  ComHandlerSend    lookupSend(final Class type);
	public  ComHandlerReceive lookupReceive(final Class type);

	
	
	public final class Default implements ComHandlerRegistry
	{
		///////////////////////////////////////////////////////////////////////////
		// constants //
		//////////////
		
		private final static Logger logger = Logging.getLogger(Default.class);
		
		///////////////////////////////////////////////////////////////////////////
		// instance fields //
		////////////////////
		
		private final MiniMap, ComHandlerSend>    sendHandlers    = new MiniMap<>();
		private final MiniMap, ComHandlerReceive> receiveHandlers = new MiniMap<>();
		
		///////////////////////////////////////////////////////////////////////////
		// constructors //
		/////////////////
		
		public Default()
		{
			super();
		}
		
		///////////////////////////////////////////////////////////////////////////
		// methods //
		////////////
		
		@Override
		public final  boolean registerSendHandler(final Class type, final ComHandlerSend handler)
		{
			logger.debug("registered sending handler {} for type {}", handler.getClass(), type);
			return this.sendHandlers.put(type, handler) != null;
		}
		
		@SuppressWarnings("unchecked")
		@Override
		public final  ComHandlerSend lookupSend(final Class type)
		{
			return (ComHandlerSend) this.sendHandlers.get(type);
		}
		
		@Override
		public final  boolean registerReceiveHandler(final Class type, final ComHandlerReceive handler)
		{
			logger.debug("registered receiving handler {} for type {}", handler.getClass(), type);
			return this.receiveHandlers.put(type, handler) != null;
		}
		
		@SuppressWarnings("unchecked")
		@Override
		public final  ComHandlerReceive lookupReceive(final Class type)
		{
			return (ComHandlerReceive) this.receiveHandlers.get(type);
		}
	}
	
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy