/*********************************************************************
* EJServerRegistry.java
* created on 18.05.2007 by netseeker
* $Id: EJServerRegistry.java,v 1.2 2007/05/28 12:42:38 netseeker Exp $
* $Log: EJServerRegistry.java,v $
* Revision 1.2 2007/05/28 12:42:38 netseeker
* *** empty log message ***
*
* Revision 1.1 2007/05/27 22:13:09 netseeker
* *** empty log message ***
*
* Revision 1.1 2007/05/22 22:50:46 netseeker
* added In-JVM processing mode, fixed a minor bug within the serverside detection of ADAPTER_STRATEGY_DIRECT.
*
*
* ====================================================================
*
* Copyright 2005-2006 netseeker aka Michael Manske
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
* ====================================================================
*
* This file is part of the EJOE framework.
* For more information on the author, please see
* <http://www.manskes.de/>.
*
*********************************************************************/
package de.netseeker.ejoe.core;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import de.netseeker.ejoe.EJServer;
import de.netseeker.ejoe.IServerInfo;
/**
* A simple registry wherein all known local EJServers are registered, so that clients lookup an EJServer within the
* same JVM.
*
* @author netseeker
* @since 0.3.9.3
*/
public class EJServerRegistry
{
private static EJServerRegistry instance = new EJServerRegistry();
private Map registry = Collections.synchronizedMap( new HashMap() );
private EJServerRegistry()
{
}
/**
* @return
*/
public static EJServerRegistry getInstance()
{
return instance;
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.ServerRegistry#lookup(java.lang.String)
*/
public EJServer lookup( String connectionInfo )
{
return (EJServer) registry.get( connectionInfo );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.ServerRegistry#lookup()
*/
public synchronized EJServer lookup()
{
EJServer server = null;
if ( registry.size() > 0 )
{
Iterator it = registry.values().iterator();
while ( it.hasNext() )
{
server = (EJServer) registry.values().iterator().next();
if ( server.isRunning() )
{
return server;
}
else
{
deRegister( server );
}
}
}
return server;
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.ServerRegistry#register(de.netseeker.ejoe.EJServer)
*/
public void register( EJServer ejserver )
{
IServerInfo serverInfo = ejserver.getServerInfo();
if ( ejserver.isRunning() )
{
registry.put( serverInfo.getInterface() + ":" + serverInfo.getPort(), ejserver );
}
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.ServerRegistry#deRegister(de.netseeker.ejoe.EJServer)
*/
public void deRegister( EJServer ejserver )
{
IServerInfo serverInfo = ejserver.getServerInfo();
registry.remove( serverInfo.getInterface() + ":" + serverInfo.getPort() );
}
}