Search in sources :

Example 16 with Version

use of org.apache.geode.internal.Version 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());
    }
}
Also used : Version(org.apache.geode.internal.Version) DataOutputStream(java.io.DataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) IOException(java.io.IOException) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) SocketAddress(java.net.SocketAddress) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) CqException(org.apache.geode.cache.query.CqException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) UnsupportedVersionException(org.apache.geode.cache.UnsupportedVersionException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CancelException(org.apache.geode.CancelException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) UnsupportedVersionException(org.apache.geode.cache.UnsupportedVersionException)

Example 17 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class Connection method readAck.

/**
   * @param msToWait number of milliseconds to wait for an ack. If 0 then wait forever.
   * @param msInterval interval between checks
   * @throws SocketTimeoutException if msToWait expires.
   * @throws ConnectionException if ack is not received (fixes bug 34312)
   */
public void readAck(final int msToWait, final long msInterval, final DirectReplyProcessor processor) throws SocketTimeoutException, ConnectionException {
    if (isSocketClosed()) {
        throw new ConnectionException(LocalizedStrings.Connection_CONNECTION_IS_CLOSED.toLocalizedString());
    }
    synchronized (this.stateLock) {
        this.connectionState = STATE_READING_ACK;
    }
    boolean origSocketInUse = this.socketInUse;
    this.socketInUse = true;
    MsgReader msgReader = null;
    DMStats stats = owner.getConduit().stats;
    final Version version = getRemoteVersion();
    try {
        if (useNIO()) {
            msgReader = new NIOMsgReader(this, version);
        } else {
            msgReader = new OioMsgReader(this, version);
        }
        Header header = msgReader.readHeader();
        ReplyMessage msg;
        int len;
        if (header.getNioMessageType() == NORMAL_MSG_TYPE) {
            msg = (ReplyMessage) msgReader.readMessage(header);
            len = header.getNioMessageLength();
        } else {
            MsgDestreamer destreamer = obtainMsgDestreamer(header.getNioMessageId(), version);
            while (header.getNioMessageType() == CHUNKED_MSG_TYPE) {
                msgReader.readChunk(header, destreamer);
                header = msgReader.readHeader();
            }
            msgReader.readChunk(header, destreamer);
            msg = (ReplyMessage) destreamer.getMessage();
            releaseMsgDestreamer(header.getNioMessageId(), destreamer);
            len = destreamer.size();
        }
        // I'd really just like to call dispatchMessage here. However,
        // that call goes through a bunch of checks that knock about
        // 10% of the performance. Since this direct-ack stuff is all
        // about performance, we'll skip those checks. Skipping them
        // should be legit, because we just sent a message so we know
        // the member is already in our view, etc.
        DistributionManager dm = (DistributionManager) owner.getDM();
        msg.setBytesRead(len);
        msg.setSender(remoteAddr);
        stats.incReceivedMessages(1L);
        stats.incReceivedBytes(msg.getBytesRead());
        stats.incMessageChannelTime(msg.resetTimestamp());
        msg.process(dm, processor);
    // dispatchMessage(msg, len, false);
    } catch (MemberShunnedException e) {
    // do nothing
    } catch (SocketTimeoutException timeout) {
        throw timeout;
    } catch (IOException e) {
        final String err = LocalizedStrings.Connection_ACK_READ_IO_EXCEPTION_FOR_0.toLocalizedString(this);
        if (!isSocketClosed()) {
            if (logger.isDebugEnabled() && !isIgnorableIOException(e)) {
                logger.debug(err, e);
            }
        }
        try {
            requestClose(err + ": " + e);
        } catch (Exception ex) {
        }
        throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
    } catch (ConnectionException e) {
        this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
        throw e;
    } catch (Exception e) {
        this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
        if (!isSocketClosed()) {
            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ACK_READ_EXCEPTION), e);
        }
        try {
            requestClose(LocalizedStrings.Connection_ACK_READ_EXCEPTION_0.toLocalizedString(e));
        } catch (Exception ex) {
        }
        throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
    } finally {
        stats.incProcessedMessages(1L);
        accessed();
        this.socketInUse = origSocketInUse;
        if (this.ackTimedOut) {
            logger.info(LocalizedMessage.create(LocalizedStrings.Connection_FINISHED_WAITING_FOR_REPLY_FROM_0, new Object[] { getRemoteAddress() }));
            this.ackTimedOut = false;
        }
        if (msgReader != null) {
            msgReader.close();
        }
    }
    synchronized (stateLock) {
        this.connectionState = STATE_RECEIVED_ACK;
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) CancelledKeyException(java.nio.channels.CancelledKeyException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ClosedSelectorException(java.nio.channels.ClosedSelectorException) SocketTimeoutException(java.net.SocketTimeoutException) Header(org.apache.geode.internal.tcp.MsgReader.Header) Version(org.apache.geode.internal.Version) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 18 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class RemoveAllPRMessage method fromData.

@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    super.fromData(in);
    this.bucketId = Integer.valueOf((int) InternalDataSerializer.readSignedVL(in));
    if ((flags & HAS_BRIDGE_CONTEXT) != 0) {
        this.bridgeContext = DataSerializer.readObject(in);
    }
    Version sourceVersion = InternalDataSerializer.getVersionForDataStream(in);
    this.callbackArg = DataSerializer.readObject(in);
    this.removeAllPRDataSize = (int) InternalDataSerializer.readUnsignedVL(in);
    this.removeAllPRData = new RemoveAllEntryData[removeAllPRDataSize];
    if (this.removeAllPRDataSize > 0) {
        final Version version = InternalDataSerializer.getVersionForDataStreamOrNull(in);
        final ByteArrayDataInput bytesIn = new ByteArrayDataInput();
        for (int i = 0; i < this.removeAllPRDataSize; i++) {
            this.removeAllPRData[i] = new RemoveAllEntryData(in, null, i, version, bytesIn);
        }
        boolean hasTags = in.readBoolean();
        if (hasTags) {
            EntryVersionsList versionTags = EntryVersionsList.create(in);
            for (int i = 0; i < this.removeAllPRDataSize; i++) {
                this.removeAllPRData[i].versionTag = versionTags.get(i);
            }
        }
    }
}
Also used : EntryVersionsList(org.apache.geode.internal.cache.DistributedPutAllOperation.EntryVersionsList) Version(org.apache.geode.internal.Version) RemoveAllEntryData(org.apache.geode.internal.cache.DistributedRemoveAllOperation.RemoveAllEntryData) ByteArrayDataInput(org.apache.geode.internal.ByteArrayDataInput)

Example 19 with Version

use of org.apache.geode.internal.Version 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)

Example 20 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class OldClientSupportProvider method processOutgoingClassName.

@Override
public String processOutgoingClassName(String name, DataOutput out) {
    // tcpserver was moved to a different package
    String oldPackage = "com.gemstone.org.jgroups.stack.tcpserver";
    String newPackage = "org.apache.geode.distributed.internal.tcpserver";
    if (name.startsWith(newPackage)) {
        return oldPackage + name.substring(newPackage.length());
    }
    if (ALWAYS_CONVERT_CLASSES) {
        return processClassName(name, GEODE, GEMFIRE, newClassNamesToOld);
    }
    // if the client is old then it needs com.gemstone.gemfire package names
    if (out instanceof VersionedDataOutputStream) {
        VersionedDataOutputStream vout = (VersionedDataOutputStream) out;
        Version version = vout.getVersion();
        if (version != null && version.compareTo(Version.GFE_90) < 0) {
            return processClassName(name, GEODE, GEMFIRE, newClassNamesToOld);
        }
    }
    return name;
}
Also used : Version(org.apache.geode.internal.Version) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream)

Aggregations

Version (org.apache.geode.internal.Version)40 IOException (java.io.IOException)16 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)10 ByteArrayDataInput (org.apache.geode.internal.ByteArrayDataInput)8 UnsupportedVersionException (org.apache.geode.cache.UnsupportedVersionException)6 EntryVersionsList (org.apache.geode.internal.cache.DistributedPutAllOperation.EntryVersionsList)6 DiskAccessException (org.apache.geode.cache.DiskAccessException)5 DataInputStream (java.io.DataInputStream)4 EOFException (java.io.EOFException)4 InterruptedIOException (java.io.InterruptedIOException)4 DataOutputStream (java.io.DataOutputStream)3 FileInputStream (java.io.FileInputStream)3 CancelException (org.apache.geode.CancelException)3 VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)3 VersionedDataOutputStream (org.apache.geode.internal.VersionedDataOutputStream)3 PutAllEntryData (org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 SocketAddress (java.net.SocketAddress)2