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

com.thomsonreuters.ema.access.ClientSession Maven / Gradle / Ivy

There is a newer version: 3.5.1.0
Show newest version
///*|-----------------------------------------------------------------------------
// *|            This source code is provided under the Apache 2.0 license      --
// *|  and is provided AS IS with no warranty or guarantee of fit for purpose.  --
// *|                See the project's LICENSE.md for details.                  --
// *|           Copyright Thomson Reuters 2016. All rights reserved.            --
///*|-----------------------------------------------------------------------------

package com.thomsonreuters.ema.access;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import com.thomsonreuters.ema.rdm.EmaRdm;
import com.thomsonreuters.upa.codec.Buffer;
import com.thomsonreuters.upa.valueadd.common.VaNode;
import com.thomsonreuters.upa.valueadd.reactor.ReactorChannel;

class ClientSession extends VaNode
{
    private LongObject _clientHandle;
    private ReactorChannel _rsslReactorChannel;
    private HashMap	_itemInfoByStreamIdMap;
    private HashMap>>_serviceGroupIdToItemInfoMap;
    private HashSet  _itemInfoByItemInfoSet = null;
    private boolean _isLogin;
    private OmmServerBaseImpl _ommServerBaseImpl;
    private boolean _removingInCloseAll;
    private boolean _isADHSession = false;
    protected int _majorVersion;
    protected int _minorVersion;

    ClientSession(OmmServerBaseImpl ommServerBaseImpl)
    {
    	_ommServerBaseImpl = ommServerBaseImpl;
    	
    	_itemInfoByStreamIdMap = new HashMap(_ommServerBaseImpl.activeConfig().itemCountHint);
    	
    	_serviceGroupIdToItemInfoMap = new HashMap<>();
    	
    	if(!_ommServerBaseImpl.activeConfig().acceptMessageSameKeyButDiffStream)
    	{
    		_itemInfoByItemInfoSet = new HashSet(_ommServerBaseImpl.activeConfig().itemCountHint);
    	}
    	
    	_clientHandle = new LongObject();
        _clientHandle.value(ServerPool.getClientHandle());
        _rsslReactorChannel = null;
        _isLogin = false;
        _removingInCloseAll = false;
    }

    LongObject clientHandle()
    {
        return _clientHandle;
    }

    void channel(ReactorChannel rsslReactorChannel)
    {
        _rsslReactorChannel = rsslReactorChannel;

        _majorVersion = rsslReactorChannel.majorVersion();
        _minorVersion = rsslReactorChannel.minorVersion();
    }

    ReactorChannel channel()
    {
        return _rsslReactorChannel;
    }

    void addItemInfo(ItemInfo itemInfo)
    {
    	_itemInfoByStreamIdMap.put(itemInfo.streamId(), itemInfo);
    }

    void removeItemInfo(ItemInfo itemInfo)
    {
    	if( _removingInCloseAll == false )
    	{
    		_itemInfoByStreamIdMap.remove(itemInfo.streamId());
    		
    		if ( _itemInfoByItemInfoSet != null )
    		{
    			if(itemInfo.domainType() > EmaRdm.MMT_DICTIONARY)
    			{
    				_itemInfoByItemInfoSet.remove(itemInfo);
    			}
    		}
    	}
    }
    
    ItemInfo getItemInfo(LongObject streamId)
    {
    	_ommServerBaseImpl.userLock().lock();
    	
    	ItemInfo itemInfo = _itemInfoByStreamIdMap.get(streamId);
    	
    	_ommServerBaseImpl.userLock().unlock();
    	
    	return itemInfo;
    }
    
    boolean checkingExistingReq(ItemInfo itemInfo)
    {
    	if ( _itemInfoByItemInfoSet == null )
    	{
    		return false;
    	}
    	
    	boolean found = false;
    	
    	_ommServerBaseImpl.userLock().lock();
    	
    	found = _itemInfoByItemInfoSet.contains(itemInfo);
    		
    	if(!found)
    	{
    		_itemInfoByItemInfoSet.add(itemInfo);
    	}
    	
    	_ommServerBaseImpl.userLock().unlock();
    	
    	return found;
    }
    
    Collection itemInfoList()
    {
    	return _itemInfoByStreamIdMap.values();
    }
    
    HashMap>> serviceGroupIdToItemInfoMap()
    {
    	return _serviceGroupIdToItemInfoMap;
    }

    void closeAllItemInfo()
    {
        if (_ommServerBaseImpl != null)
        {	
        	_removingInCloseAll = true;
        	
        	Iterator iter = _itemInfoByStreamIdMap.values().iterator();
        	
        	ItemInfo itemInfo;
        	
        	while(iter.hasNext())
        	{
        		itemInfo = iter.next();
        		
        		switch(itemInfo.domainType())
        		{
        		case EmaRdm.MMT_DICTIONARY:
        			_ommServerBaseImpl._dictionaryHandler.getItemInfoList().remove(itemInfo);
        			break;
        		case EmaRdm.MMT_DIRECTORY:
        			_ommServerBaseImpl._directoryHandler.getItemInfoList().remove(itemInfo);
        			break;
        		case EmaRdm.MMT_LOGIN:
        			_ommServerBaseImpl._loginHandler.getItemInfoList().remove(itemInfo);
        			break;
        		default:
        			break;
        		}
        		
        		_ommServerBaseImpl.removeItemInfo(itemInfo, false);
        	}
        	
        	_itemInfoByStreamIdMap.clear();
        	
        	Iterator>> groupIdToItemInfoIt =  _serviceGroupIdToItemInfoMap.values().iterator();
        	
        	while(groupIdToItemInfoIt.hasNext())
        	{
        		HashMap> groupIdToItemInfo = groupIdToItemInfoIt.next();
        		
        		Iterator> itemInfoListIt = groupIdToItemInfo.values().iterator();
        		
        		while(itemInfoListIt.hasNext())
        		{
        			itemInfoListIt.next().clear();
        		}
        		
        		groupIdToItemInfo.clear();
        	}
        	
        	_serviceGroupIdToItemInfoMap.clear();
        	
        	if ( _itemInfoByItemInfoSet != null )
        	{
        		_itemInfoByItemInfoSet.clear();
        	}
        	
        	_removingInCloseAll = false;
        }
    }

    public String toString()
    {
        String returnString = "\tClient handle = " + _clientHandle;

        return returnString;
    }

    void isLogin(boolean isLogin)
    {
        _isLogin = isLogin;
    }

    boolean isADHSession()
    {
        return _isADHSession;
    }
    
    void isADHSession(boolean isADHSession)
    {
    	_isADHSession = isADHSession;
    }

    boolean isLogin()
    {
        return _isLogin;
    }

    void clear()
    {
    	_itemInfoByStreamIdMap.clear();
    	_serviceGroupIdToItemInfoMap.clear();
    	
    	if ( _itemInfoByItemInfoSet != null )
    	{
    		_itemInfoByItemInfoSet.clear();
    	}
    	
        _rsslReactorChannel = null;
        _isLogin = false;
        _removingInCloseAll = false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy