use of org.apache.geode.cache.UnsupportedVersionException 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) {
}
}
}
}
use of org.apache.geode.cache.UnsupportedVersionException in project geode by apache.
the class CacheClientNotifier method registerClient.
/**
* Registers a new client updater that wants to receive updates with this server.
*
* @param socket The socket over which the server communicates with the client.
*/
public void registerClient(Socket socket, boolean isPrimary, long acceptorId, boolean notifyBySubscription) throws IOException {
// Since no remote ports were specified in the message, wait for them.
long startTime = this.statistics.startTime();
DataInputStream dis = new DataInputStream(socket.getInputStream());
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
// Read the client version
short clientVersionOrdinal = Version.readOrdinal(dis);
Version clientVersion = null;
try {
clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
if (logger.isDebugEnabled()) {
logger.debug("{}: Registering client with version: {}", this, clientVersion);
}
} catch (UnsupportedVersionException e) {
SocketAddress sa = socket.getRemoteSocketAddress();
UnsupportedVersionException uve = e;
if (sa != null) {
String sInfo = " Client: " + sa.toString() + ".";
uve = new UnsupportedVersionException(e.getMessage() + sInfo);
}
logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientNotifier_CACHECLIENTNOTIFIER_CAUGHT_EXCEPTION_ATTEMPTING_TO_CLIENT), uve);
writeException(dos, Acceptor.UNSUCCESSFUL_SERVER_TO_CLIENT, uve, clientVersion);
return;
}
// Read and ignore the reply code. This is used on the client to server
// handshake.
// replyCode
dis.readByte();
if (Version.GFE_57.compareTo(clientVersion) <= 0) {
if (Version.CURRENT.compareTo(clientVersion) > 0) {
dis = new VersionedDataInputStream(dis, clientVersion);
dos = new VersionedDataOutputStream(dos, clientVersion);
}
registerGFEClient(dis, dos, socket, isPrimary, startTime, clientVersion, acceptorId, notifyBySubscription);
} else {
Exception e = new UnsupportedVersionException(clientVersionOrdinal);
throw new IOException(e.toString());
}
}
use of org.apache.geode.cache.UnsupportedVersionException in project geode by apache.
the class TcpClient method requestToServer.
/**
* Send a request to a Locator
*
* @param ipAddr The locator's inet socket address
* @param request The request message
* @param timeout Timeout for sending the message and receiving a reply
* @param replyExpected Whether to wait for a reply
*
* @return The reply, or null if no reply is expected
*
* @throws IOException
* @throws ClassNotFoundException
*/
public Object requestToServer(InetSocketAddress ipAddr, Object request, int timeout, boolean replyExpected) throws IOException, ClassNotFoundException {
/*
* InetSocketAddress ipAddr; if (addr == null) { ipAddr = new InetSocketAddress(port); } else {
* ipAddr = new InetSocketAddress(addr, port); // fix for bug 30810 }
*/
long giveupTime = System.currentTimeMillis() + timeout;
// Get the GemFire version of the TcpServer first, before sending any other request.
short serverVersion = getServerVersion(ipAddr, timeout).shortValue();
if (serverVersion > Version.CURRENT_ORDINAL) {
serverVersion = Version.CURRENT_ORDINAL;
}
// establish the old GossipVersion for the server
int gossipVersion = TcpServer.getCurrentGossipVersion();
if (Version.GFE_71.compareTo(serverVersion) > 0) {
gossipVersion = TcpServer.getOldGossipVersion();
}
long newTimeout = giveupTime - System.currentTimeMillis();
if (newTimeout <= 0) {
return null;
}
logger.debug("TcpClient sending {} to {}", request, ipAddr);
Socket sock = socketCreator.connect(ipAddr.getAddress(), ipAddr.getPort(), (int) newTimeout, null, false);
sock.setSoTimeout((int) newTimeout);
DataOutputStream out = null;
try {
out = new DataOutputStream(sock.getOutputStream());
if (serverVersion < Version.CURRENT_ORDINAL) {
out = new VersionedDataOutputStream(out, Version.fromOrdinalNoThrow(serverVersion, false));
}
out.writeInt(gossipVersion);
if (gossipVersion > TcpServer.getOldGossipVersion()) {
out.writeShort(serverVersion);
}
DataSerializer.writeObject(request, out);
out.flush();
if (replyExpected) {
DataInputStream in = new DataInputStream(sock.getInputStream());
in = new VersionedDataInputStream(in, Version.fromOrdinal(serverVersion, false));
try {
Object response = DataSerializer.readObject(in);
logger.debug("received response: {}", response);
return response;
} catch (EOFException ex) {
EOFException eof = new EOFException("Locator at " + ipAddr + " did not respond. This is normal if the locator was shutdown. If it wasn't check its log for exceptions.");
eof.initCause(ex);
throw eof;
}
} else {
return null;
}
} catch (UnsupportedVersionException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Remote TcpServer version: " + serverVersion + " is higher than local version: " + Version.CURRENT_ORDINAL + ". This is never expected as remoteVersion");
}
return null;
} finally {
try {
if (replyExpected) {
// the locator's machine.
if (!sock.isClosed() && !socketCreator.useSSL()) {
sock.setSoLinger(true, 0);
}
}
sock.close();
} catch (Exception e) {
logger.error("Error closing socket ", e);
}
if (out != null) {
out.close();
}
}
}
use of org.apache.geode.cache.UnsupportedVersionException in project geode by apache.
the class Oplog method readProductVersionRecord.
private Version readProductVersionRecord(DataInput dis, File f) throws IOException {
Version recoveredGFVersion;
short ver = Version.readOrdinal(dis);
try {
recoveredGFVersion = Version.fromOrdinal(ver, false);
} catch (UnsupportedVersionException e) {
throw new DiskAccessException(LocalizedStrings.Oplog_UNEXPECTED_PRODUCT_VERSION_0.toLocalizedString(ver), e, getParent());
}
logger.trace(LogMarker.PERSIST_RECOVERY, "version={}", recoveredGFVersion);
readEndOfRecord(dis);
return recoveredGFVersion;
}
use of org.apache.geode.cache.UnsupportedVersionException in project geode by apache.
the class ReplyProcessor21 method processException.
/**
* Handle a {@link DSFIDNotFoundException} indicating a message type is not implemented on another
* server (for example due to different product version). Default implementation logs the
* exception as severe and moves on.
*
* Rationale for default handling: New operations can have caused changes to other newer versioned
* GFE JVMs that cannot be reverted. So ignoring exceptions is a conservative way considering such
* scenarios. It will be upto individual messages to handle differently by overriding the above
* method.
*/
protected synchronized void processException(DistributionMessage msg, DSFIDNotFoundException ex) {
final short versionOrdinal = ex.getProductVersionOrdinal();
String versionStr = null;
try {
Version version = Version.fromOrdinal(versionOrdinal, false);
versionStr = version.toString();
} catch (UnsupportedVersionException e) {
}
if (versionStr == null) {
versionStr = "Ordinal=" + versionOrdinal;
}
logger.fatal(LocalizedMessage.create(LocalizedStrings.ReplyProcessor21_UNKNOWN_DSFID_ERROR, new Object[] { ex.getUnknownDSFID(), msg.getSender(), versionStr }), ex);
}
Aggregations