Skip to content
Snippets Groups Projects
Commit b727a045 authored by cramakri's avatar cramakri
Browse files

LMS-1527 Moved RpcServiceNameServer to common.

SVN: 15867
parent d108e931
No related merge requests found
/*
* Copyright 2010 ETH Zuerich, CISD
*
* 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.
*/
package ch.systemsx.cisd.common.api;
/**
* The most generic interface for RPC invocations into openBIS.
* <p>
* This interface defines a minimal interface presented by RPC services. It lets clients determine
* which version of the interface the server supports. To do anything interesting, clients need to
* get a reference to a specific interface using the {@link IRpcServiceNameServer}.
*
* @author Chandrasekhar Ramakrishnan
*/
public interface IRpcService
{
//
// Protocol versioning
//
/**
* Returns the major version of the server side interface. Different major versions are
* incompatible with one another.
*/
public int getMajorVersion();
/**
* Returns the minor version of this server side interface. Different minor versions, within the
* same major version, are compatible with one another.
*/
public int getMinorVersion();
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* 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.
*/
package ch.systemsx.cisd.common.api;
import java.util.List;
/**
* An Interface for finding out about the IRpcService interfaces supported by a server.
*
* @author Chandrasekhar Ramakrishnan
*/
public interface IRpcServiceNameServer extends IRpcService
{
List<RpcServiceInterfaceDTO> getSupportedInterfaces();
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* 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.
*/
package ch.systemsx.cisd.common.api;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Describes an RPC interface supported by the server.
*
* @author Chandrasekhar Ramakrishnan
*/
public class RpcServiceInterfaceDTO implements Serializable
{
private static final long serialVersionUID = 1L;
private String interfaceName;
private final ArrayList<RpcServiceInterfaceVersionDTO> versions =
new ArrayList<RpcServiceInterfaceVersionDTO>();
public RpcServiceInterfaceDTO()
{
interfaceName = "Unknown";
}
/**
* The name of this interface used for identification.
*/
public String getInterfaceName()
{
return interfaceName;
}
public void setInterfaceName(String interfaceName)
{
this.interfaceName = interfaceName;
}
public ArrayList<RpcServiceInterfaceVersionDTO> getVersions()
{
return versions;
}
public void addVersion(RpcServiceInterfaceVersionDTO ifaceVersion)
{
versions.add(ifaceVersion);
}
@Override
public boolean equals(Object obj)
{
if (false == obj instanceof RpcServiceInterfaceDTO)
return false;
RpcServiceInterfaceDTO other = (RpcServiceInterfaceDTO) obj;
return getInterfaceName().equals(other.getInterfaceName())
&& getVersions().equals(other.getVersions());
}
@Override
public int hashCode()
{
int hash = getInterfaceName().hashCode();
hash = hash * 31 + getVersions().hashCode();
return hash;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("RpcServiceInterfaceDTO[");
sb.append(getInterfaceName());
sb.append(" ");
sb.append(getVersions().toString());
sb.append("]");
return sb.toString();
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* 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.
*/
package ch.systemsx.cisd.common.api;
import java.io.Serializable;
/**
* Describes an RPC interface supported by the server.
*
* @author Chandrasekhar Ramakrishnan
*/
public class RpcServiceInterfaceVersionDTO implements Serializable
{
private static final long serialVersionUID = 1L;
private String interfaceName;
private String interfaceUrlSuffix;
private int interfaceMajorVersion;
private int interfaceMinorVersion;
public RpcServiceInterfaceVersionDTO()
{
interfaceName = "Unknown";
interfaceUrlSuffix = "unknown";
interfaceMajorVersion = 0;
interfaceMinorVersion = 0;
}
/**
* The name of this interface used for identification.
*/
public String getInterfaceName()
{
return interfaceName;
}
public void setInterfaceName(String interfaceName)
{
this.interfaceName = interfaceName;
}
/**
* The suffix added to the server's URL to produce the URL for this interface. Used by a service
* factory to create a proxy to the service.
*/
public String getInterfaceUrlSuffix()
{
return interfaceUrlSuffix;
}
public void setInterfaceUrlSuffix(String interfaceUrlSuffix)
{
this.interfaceUrlSuffix = interfaceUrlSuffix;
}
/**
* The major version of the interface. E.g., an interface with version 2.11 has major version 2.
*/
public int getInterfaceMajorVersion()
{
return interfaceMajorVersion;
}
public void setInterfaceMajorVersion(int interfaceMajorVersion)
{
this.interfaceMajorVersion = interfaceMajorVersion;
}
/**
* The major version of the interface. E.g., an interface with version 2.11 has minor version
* 11.
*/
public int getInterfaceMinorVersion()
{
return interfaceMinorVersion;
}
public void setInterfaceMinorVersion(int interfaceMinorVersion)
{
this.interfaceMinorVersion = interfaceMinorVersion;
}
@Override
public boolean equals(Object obj)
{
if (false == obj instanceof RpcServiceInterfaceVersionDTO)
return false;
RpcServiceInterfaceVersionDTO other = (RpcServiceInterfaceVersionDTO) obj;
return getInterfaceName().equals(other.getInterfaceName())
&& getInterfaceUrlSuffix().equals(other.getInterfaceUrlSuffix())
&& getInterfaceMajorVersion() == other.getInterfaceMajorVersion()
&& getInterfaceMinorVersion() == other.getInterfaceMinorVersion();
}
@Override
public int hashCode()
{
int hash = getInterfaceName().hashCode();
hash = hash * 31 + getInterfaceUrlSuffix().hashCode();
hash = hash * 31 + getInterfaceMajorVersion();
hash = hash * 31 + getInterfaceMinorVersion();
return hash;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("RpcServiceInterfaceVersionDTO[");
sb.append(getInterfaceName());
sb.append(",");
sb.append(getInterfaceUrlSuffix());
sb.append(",v.");
sb.append(getInterfaceMajorVersion());
sb.append(".");
sb.append(getInterfaceMinorVersion());
sb.append("]");
return sb.toString();
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* 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.
*/
package ch.systemsx.cisd.common.api.server;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.api.IRpcServiceNameServer;
import ch.systemsx.cisd.common.api.RpcServiceInterfaceDTO;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
/**
* Implementation of the {@link IRpcServiceNameServer} interface which registry for accessing the
* RPC services supported by a server.
*
* @author Chandrasekhar Ramakrishnan
*/
public class RpcServiceNameServer implements IRpcServiceNameServer
{
private final ArrayList<RpcServiceInterfaceDTO> supportedInterfaces;
static private final Logger operationLog =
LogFactory.getLogger(LogCategory.OPERATION, RpcServiceNameServer.class);
RpcServiceNameServer()
{
supportedInterfaces = new ArrayList<RpcServiceInterfaceDTO>();
}
public List<RpcServiceInterfaceDTO> getSupportedInterfaces()
{
return supportedInterfaces;
}
public int getMajorVersion()
{
return 1;
}
public int getMinorVersion()
{
return 0;
}
/**
* Add an interface to the registry.
*/
public void addSupportedInterface(RpcServiceInterfaceDTO iface)
{
supportedInterfaces.add(iface);
operationLog.info("Registered RPC Interface " + iface.toString());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment