Search in sources :

Example 16 with NotSerializableException

use of java.io.NotSerializableException in project geode by apache.

the class DirectChannel method sendToMany.

/**
   * Sends a msg to a list of destinations. This code does some special optimizations to stream
   * large messages
   * 
   * @param mgr - the membership manager
   * @param p_destinations - the list of addresses to send the message to.
   * @param msg - the message to send
   * @param ackWaitThreshold
   * @param ackSAThreshold the severe alert threshold
   * @return number of bytes sent
   * @throws ConnectExceptions if message could not be send to its <code>destination</code>
   * @throws NotSerializableException If the msg cannot be serialized
   */
private int sendToMany(final MembershipManager mgr, InternalDistributedMember[] p_destinations, final DistributionMessage msg, long ackWaitThreshold, long ackSAThreshold) throws ConnectExceptions, NotSerializableException {
    InternalDistributedMember[] destinations = p_destinations;
    // Collects connect exceptions that happened during previous attempts to send.
    // These represent members we are not able to distribute to.
    ConnectExceptions failedCe = null;
    // Describes the destinations that we need to retry the send to.
    ConnectExceptions retryInfo = null;
    int bytesWritten = 0;
    boolean retry = false;
    final boolean orderedMsg = msg.orderedDelivery() || Connection.isDominoThread();
    // Connections we actually sent messages to.
    final List totalSentCons = new ArrayList(destinations.length);
    boolean interrupted = false;
    long ackTimeout = 0;
    long ackSDTimeout = 0;
    long startTime = 0;
    final DirectReplyMessage directMsg;
    if (msg instanceof DirectReplyMessage) {
        directMsg = (DirectReplyMessage) msg;
    } else {
        directMsg = null;
    }
    if (directMsg != null || msg.getProcessorId() > 0) {
        ackTimeout = (int) (ackWaitThreshold * 1000);
        if (msg.isSevereAlertCompatible() || ReplyProcessor21.isSevereAlertProcessingForced()) {
            ackSDTimeout = (int) (ackSAThreshold * 1000);
            if (ReplyProcessor21.getShortSevereAlertProcessing()) {
                ackSDTimeout = (int) (ReplyProcessor21.PR_SEVERE_ALERT_RATIO * ackSDTimeout);
            }
        }
    }
    boolean directReply = false;
    if (directMsg != null && directMsg.supportsDirectAck() && threadOwnsResources()) {
        directReply = true;
    }
    // use a regular reply processor.
    if (!directReply && directMsg != null) {
        directMsg.registerProcessor();
    }
    try {
        do {
            interrupted = interrupted || Thread.interrupted();
            /**
         * Exceptions that happened during one attempt to send
         */
            if (retryInfo != null) {
                // need to retry to each of the guys in the exception
                List retryMembers = retryInfo.getMembers();
                InternalDistributedMember[] retryDest = new InternalDistributedMember[retryMembers.size()];
                retryDest = (InternalDistributedMember[]) retryMembers.toArray(retryDest);
                destinations = retryDest;
                retryInfo = null;
                retry = true;
            }
            final List cons = new ArrayList(destinations.length);
            ConnectExceptions ce = getConnections(mgr, msg, destinations, orderedMsg, retry, ackTimeout, ackSDTimeout, cons);
            if (directReply && msg.getProcessorId() > 0) {
                // no longer a direct-reply message?
                directReply = false;
            }
            if (ce != null) {
                if (failedCe != null) {
                    failedCe.getMembers().addAll(ce.getMembers());
                    failedCe.getCauses().addAll(ce.getCauses());
                } else {
                    failedCe = ce;
                }
                ce = null;
            }
            if (cons.isEmpty()) {
                if (failedCe != null) {
                    throw failedCe;
                }
                return bytesWritten;
            }
            boolean sendingToGroup = cons.size() > 1;
            Connection permissionCon = null;
            if (sendingToGroup) {
                acquireGroupSendPermission(orderedMsg);
            } else {
                // sending to just one guy
                permissionCon = (Connection) cons.get(0);
                if (permissionCon != null) {
                    try {
                        permissionCon.acquireSendPermission();
                    } catch (ConnectionException conEx) {
                        // Set retryInfo and then retry.
                        // We want to keep calling TCPConduit.getConnection until it doesn't
                        // return a connection.
                        retryInfo = new ConnectExceptions();
                        retryInfo.addFailure(permissionCon.getRemoteAddress(), conEx);
                        continue;
                    }
                }
            }
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("{}{}) to {} peers ({}) via tcp/ip", (retry ? "Retrying send (" : "Sending ("), msg, cons.size(), cons);
                }
                DMStats stats = getDMStats();
                // used for cons we sent to this time
                List<?> sentCons;
                final BaseMsgStreamer ms = MsgStreamer.create(cons, msg, directReply, stats);
                try {
                    startTime = 0;
                    if (ackTimeout > 0) {
                        startTime = System.currentTimeMillis();
                    }
                    ms.reserveConnections(startTime, ackTimeout, ackSDTimeout);
                    int result = ms.writeMessage();
                    if (bytesWritten == 0) {
                        // bytesWritten only needs to be set once.
                        // if we have to do a retry we don't want to count
                        // each one's bytes.
                        bytesWritten = result;
                    }
                    ce = ms.getConnectExceptions();
                    sentCons = ms.getSentConnections();
                    totalSentCons.addAll(sentCons);
                } catch (NotSerializableException e) {
                    throw e;
                } catch (ToDataException e) {
                    throw e;
                } catch (IOException ex) {
                    throw new InternalGemFireException(LocalizedStrings.DirectChannel_UNKNOWN_ERROR_SERIALIZING_MESSAGE.toLocalizedString(), ex);
                } finally {
                    try {
                        ms.close();
                    } catch (IOException e) {
                        throw new InternalGemFireException("Unknown error serializing message", e);
                    }
                }
                if (ce != null) {
                    retryInfo = ce;
                    ce = null;
                }
                if (directReply && !sentCons.isEmpty()) {
                    long readAckStart = 0;
                    if (stats != null) {
                        readAckStart = stats.startReplyWait();
                    }
                    try {
                        ce = readAcks(sentCons, startTime, ackTimeout, ackSDTimeout, ce, directMsg.getDirectReplyProcessor());
                    } finally {
                        if (stats != null) {
                            stats.endReplyWait(readAckStart, startTime);
                        }
                    }
                }
            } finally {
                if (sendingToGroup) {
                    releaseGroupSendPermission(orderedMsg);
                } else if (permissionCon != null) {
                    permissionCon.releaseSendPermission();
                }
            }
            if (ce != null) {
                if (retryInfo != null) {
                    retryInfo.getMembers().addAll(ce.getMembers());
                    retryInfo.getCauses().addAll(ce.getCauses());
                } else {
                    retryInfo = ce;
                }
                ce = null;
            }
            if (retryInfo != null) {
                this.conduit.getCancelCriterion().checkCancelInProgress(null);
            }
        } while (retryInfo != null);
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
        for (Iterator it = totalSentCons.iterator(); it.hasNext(); ) {
            Connection con = (Connection) it.next();
            con.setInUse(false, 0, 0, 0, null);
        }
    }
    if (failedCe != null) {
        throw failedCe;
    }
    return bytesWritten;
}
Also used : IOException(java.io.IOException) DirectReplyMessage(org.apache.geode.internal.cache.DirectReplyMessage) NotSerializableException(java.io.NotSerializableException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember)

Example 17 with NotSerializableException

use of java.io.NotSerializableException in project geode by apache.

the class GMSMembershipManager method directChannelSend.

/**
   * Perform the grossness associated with sending a message over a DirectChannel
   *
   * @param destinations the list of destinations
   * @param content the message
   * @param theStats the statistics object to update
   * @return all recipients who did not receive the message (null if all received it)
   * @throws NotSerializableException if the message is not serializable
   */
protected Set<InternalDistributedMember> directChannelSend(InternalDistributedMember[] destinations, DistributionMessage content, DMStats theStats) throws NotSerializableException {
    boolean allDestinations;
    InternalDistributedMember[] keys;
    if (content.forAll()) {
        allDestinations = true;
        latestViewReadLock.lock();
        try {
            List<InternalDistributedMember> keySet = latestView.getMembers();
            keys = new InternalDistributedMember[keySet.size()];
            keys = keySet.toArray(keys);
        } finally {
            latestViewReadLock.unlock();
        }
    } else {
        allDestinations = false;
        keys = destinations;
    }
    int sentBytes;
    try {
        sentBytes = directChannel.send(this, keys, content, this.services.getConfig().getDistributionConfig().getAckWaitThreshold(), this.services.getConfig().getDistributionConfig().getAckSevereAlertThreshold());
        if (theStats != null) {
            theStats.incSentBytes(sentBytes);
        }
        if (sentBytes == 0) {
            if (services.getCancelCriterion().isCancelInProgress()) {
                throw new DistributedSystemDisconnectedException();
            }
        }
    } catch (DistributedSystemDisconnectedException ex) {
        if (services.getShutdownCause() != null) {
            throw new DistributedSystemDisconnectedException("DistributedSystem is shutting down", services.getShutdownCause());
        } else {
            // see bug 41416
            throw ex;
        }
    } catch (ConnectExceptions ex) {
        // Check if the connect exception is due to system shutting down.
        if (shutdownInProgress()) {
            if (services.getShutdownCause() != null) {
                throw new DistributedSystemDisconnectedException("DistributedSystem is shutting down", services.getShutdownCause());
            } else {
                throw new DistributedSystemDisconnectedException();
            }
        }
        if (allDestinations)
            return null;
        // We
        List<InternalDistributedMember> members = (List<InternalDistributedMember>) ex.getMembers();
        // need
        // to
        // return
        // this
        // list
        // of
        // failures
        // SANITY CHECK: If we fail to send a message to an existing member
        // of the view, we have a serious error (bug36202).
        // grab a recent view, excluding shunned
        NetView view = services.getJoinLeave().getView();
        // members
        // Iterate through members and causes in tandem :-(
        Iterator it_mem = members.iterator();
        Iterator it_causes = ex.getCauses().iterator();
        while (it_mem.hasNext()) {
            InternalDistributedMember member = (InternalDistributedMember) it_mem.next();
            Throwable th = (Throwable) it_causes.next();
            if (!view.contains(member) || (th instanceof ShunnedMemberException)) {
                continue;
            }
            logger.fatal(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_FAILED_TO_SEND_MESSAGE_0_TO_MEMBER_1_VIEW_2, new Object[] { content, member, view }), th);
        // Assert.assertTrue(false, "messaging contract failure");
        }
        return new HashSet<>(members);
    }// catch ConnectionExceptions
     catch (ToDataException | CancelException e) {
        throw e;
    } catch (IOException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Membership: directChannelSend caught exception: {}", e.getMessage(), e);
        }
        if (e instanceof NotSerializableException) {
            throw (NotSerializableException) e;
        }
    } catch (RuntimeException | Error e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Membership: directChannelSend caught exception: {}", e.getMessage(), e);
        }
        throw e;
    }
    return null;
}
Also used : ShunnedMemberException(org.apache.geode.distributed.internal.direct.ShunnedMemberException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) ConnectExceptions(org.apache.geode.internal.tcp.ConnectExceptions) NetView(org.apache.geode.distributed.internal.membership.NetView) InternalGemFireError(org.apache.geode.InternalGemFireError) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ToDataException(org.apache.geode.ToDataException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException)

Example 18 with NotSerializableException

use of java.io.NotSerializableException in project geode by apache.

the class DirectReplySender method putOutgoing.

public Set putOutgoing(DistributionMessage msg) {
    Assert.assertTrue(!this.sentReply, "Trying to reply twice to a message");
    // Using an ArrayList, rather than Collections.singletonList here, because the MsgStreamer
    // mutates the list when it has exceptions.
    // fix for bug #42199 - cancellation check
    this.conn.getConduit().getDM().getCancelCriterion().checkCancelInProgress(null);
    if (logger.isTraceEnabled(LogMarker.DM)) {
        logger.trace(LogMarker.DM, "Sending a direct reply {} to {}", msg, conn.getRemoteAddress());
    }
    ArrayList<Connection> conns = new ArrayList<Connection>(1);
    conns.add(conn);
    MsgStreamer ms = (MsgStreamer) MsgStreamer.create(conns, msg, false, DUMMY_STATS);
    try {
        ms.writeMessage();
        ConnectExceptions ce = ms.getConnectExceptions();
        if (ce != null && !ce.getMembers().isEmpty()) {
            Assert.assertTrue(ce.getMembers().size() == 1);
            logger.warn(LocalizedMessage.create(LocalizedStrings.DirectChannel_FAILURE_SENDING_DIRECT_REPLY, ce.getMembers().iterator().next()));
            return Collections.singleton(ce.getMembers().iterator().next());
        }
        sentReply = true;
        return Collections.emptySet();
    } catch (NotSerializableException e) {
        throw new InternalGemFireException(e);
    } catch (ToDataException e) {
        // exception from user code
        throw e;
    } catch (IOException ex) {
        throw new InternalGemFireException(LocalizedStrings.DirectChannel_UNKNOWN_ERROR_SERIALIZING_MESSAGE.toLocalizedString(), ex);
    } finally {
        try {
            ms.close();
        } catch (IOException e) {
            throw new InternalGemFireException("Unknown error serializing message", e);
        }
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) InternalGemFireException(org.apache.geode.InternalGemFireException) ToDataException(org.apache.geode.ToDataException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 19 with NotSerializableException

use of java.io.NotSerializableException in project geode by apache.

the class FunctionStreamingReplyMessage method toData.

@Override
public void toData(DataOutput out) throws IOException {
    super.toData(out);
    out.writeInt(this.msgNum);
    out.writeBoolean(this.lastMsg);
    out.writeInt(this.processorId);
    // soubhik. fix for ticket 40670
    try {
        DataSerializer.writeObject(this.result, out);
    } catch (Exception ex) {
        if (ex instanceof CancelException) {
            throw new DistributedSystemDisconnectedException(ex);
        }
        NotSerializableException ioEx = new NotSerializableException(this.result.getClass().getName());
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) NotSerializableException(java.io.NotSerializableException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ReplyException(org.apache.geode.distributed.internal.ReplyException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException)

Example 20 with NotSerializableException

use of java.io.NotSerializableException in project ignite by apache.

the class OptimizedObjectStreamSelfTest method testRequireSerializable.

/**
     * @throws Exception If failed.
     */
public void testRequireSerializable() throws Exception {
    try {
        OptimizedMarshaller marsh = new OptimizedMarshaller(true);
        marsh.setContext(CTX);
        marsh.marshal(new Object());
        assert false : "Exception not thrown.";
    } catch (IgniteCheckedException e) {
        NotSerializableException serEx = e.getCause(NotSerializableException.class);
        if (serEx == null)
            throw e;
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) OptimizedMarshaller(org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller)

Aggregations

NotSerializableException (java.io.NotSerializableException)39 ObjectOutputStream (java.io.ObjectOutputStream)14 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectInputStream (java.io.ObjectInputStream)9 Test (org.junit.Test)9 Person (com.alibaba.dubbo.common.model.Person)7 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)7 ArrayList (java.util.ArrayList)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)5 InvalidClassException (java.io.InvalidClassException)4 OptionalDataException (java.io.OptionalDataException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)3