Search in sources :

Example 1 with IncompatibleVersionException

use of org.apache.geode.cache.IncompatibleVersionException in project geode by apache.

the class ServerHandShakeProcessor method readClientVersion.

private static Version readClientVersion(ServerConnection connection) throws IOException, VersionException {
    Socket socket = connection.getSocket();
    int timeout = connection.getHandShakeTimeout();
    int soTimeout = -1;
    try {
        soTimeout = socket.getSoTimeout();
        socket.setSoTimeout(timeout);
        InputStream is = socket.getInputStream();
        short clientVersionOrdinal = Version.readOrdinalFromInputStream(is);
        if (clientVersionOrdinal == -1) {
            throw new EOFException(LocalizedStrings.ServerHandShakeProcessor_HANDSHAKEREADER_EOF_REACHED_BEFORE_CLIENT_VERSION_COULD_BE_READ.toLocalizedString());
        }
        Version clientVersion = null;
        try {
            clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
        } catch (UnsupportedVersionException uve) {
            // Allows higher version of wan site to connect to server
            if (connection.getCommunicationMode() == Acceptor.GATEWAY_TO_GATEWAY && !(clientVersionOrdinal == Version.NOT_SUPPORTED_ORDINAL)) {
                return Acceptor.VERSION;
            } else {
                SocketAddress sa = socket.getRemoteSocketAddress();
                String sInfo = "";
                if (sa != null) {
                    sInfo = " Client: " + sa.toString() + ".";
                }
                throw new UnsupportedVersionException(uve.getMessage() + sInfo);
            }
        }
        if (!clientVersion.compatibleWith(Acceptor.VERSION)) {
            // we can throw this
            throw new IncompatibleVersionException(clientVersion, Acceptor.VERSION);
        // to restrict
        }
        // Backward Compatibilty Support to limited no of versions
        return clientVersion;
    } finally {
        if (soTimeout != -1) {
            try {
                socket.setSoTimeout(soTimeout);
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : Version(org.apache.geode.internal.Version) InputStream(java.io.InputStream) IncompatibleVersionException(org.apache.geode.cache.IncompatibleVersionException) EOFException(java.io.EOFException) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) Socket(java.net.Socket) UnsupportedVersionException(org.apache.geode.cache.UnsupportedVersionException)

Aggregations

EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Socket (java.net.Socket)1 SocketAddress (java.net.SocketAddress)1 IncompatibleVersionException (org.apache.geode.cache.IncompatibleVersionException)1 UnsupportedVersionException (org.apache.geode.cache.UnsupportedVersionException)1 Version (org.apache.geode.internal.Version)1