use of org.apache.geode.ToDataException 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);
}
}
}
use of org.apache.geode.ToDataException in project geode by apache.
the class Bug40751DUnitTest method testRR.
@Test
public void testRR() {
System.setProperty("p2p.nodirectBuffers", "true");
try {
Host host = Host.getHost(0);
VM vm0 = host.getVM(1);
VM vm1 = host.getVM(2);
SerializableRunnable createDataRegion = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
attr.setScope(Scope.DISTRIBUTED_ACK);
attr.setDataPolicy(DataPolicy.REPLICATE);
attr.setMulticastEnabled(true);
cache.createRegion("region1", attr.create());
}
};
vm0.invoke(createDataRegion);
SerializableRunnable createEmptyRegion = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
attr.setScope(Scope.DISTRIBUTED_ACK);
attr.setDataPolicy(DataPolicy.EMPTY);
Region region = cache.createRegion("region1", attr.create());
try {
region.put("A", new MyClass());
fail("expected ToDataException");
} catch (ToDataException ex) {
if (!(ex.getCause() instanceof RuntimeException)) {
fail("expected RuntimeException instead of " + ex.getCause());
}
}
}
};
vm1.invoke(createEmptyRegion);
} finally {
Invoke.invokeInEveryVM(new SerializableCallable() {
public Object call() throws Exception {
System.getProperties().remove("p2p.oldIO");
System.getProperties().remove("p2p.nodirectBuffers");
return null;
}
});
System.getProperties().remove("p2p.oldIO");
System.getProperties().remove("p2p.nodirectBuffers");
}
}
use of org.apache.geode.ToDataException in project geode by apache.
the class DistributionManager method sendMessage.
/**
* @return recipients who did not receive the message
* @throws NotSerializableException If <codE>message</code> cannot be serialized
*/
Set sendMessage(DistributionMessage message) throws NotSerializableException {
Set result = null;
try {
// Verify we're not too far into the shutdown
stopper.checkCancelInProgress(null);
// avoid race condition during startup
waitUntilReadyToSendMsgs(message);
result = sendOutgoing(message);
} catch (NotSerializableException ex) {
// serialization error in user data
throw ex;
} catch (ToDataException ex) {
// serialization error in user data
throw ex;
} catch (ReenteredConnectException ex) {
// Recursively tried to get the same connection
throw ex;
} catch (CancelException ex) {
// bug 37194, shutdown conditions
throw ex;
} catch (InvalidDeltaException ide) {
logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_CAUGHT_EXCEPTION_WHILE_SENDING_DELTA), ide.getCause());
throw (RuntimeException) ide.getCause();
} catch (Exception ex) {
DistributionManager.this.exceptionInThreads = true;
String receiver = "NULL";
if (message != null) {
receiver = message.getRecipientsDescription();
}
logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributionManager_WHILE_PUSHING_MESSAGE_0_TO_1, new Object[] { message, receiver }), ex);
if (message == null || message.forAll())
return null;
result = new HashSet();
for (int i = 0; i < message.getRecipients().length; i++) result.add(message.getRecipients()[i]);
return result;
/*
* if (ex instanceof org.apache.geode.GemFireIpcResourceException) { return; }
*/
}
return result;
}
use of org.apache.geode.ToDataException in project geode by apache.
the class InternalDataSerializer method invokeToData.
/**
* For backward compatibility this method should be used to invoke toData on a DSFID or
* DataSerializable. It will invoke the correct toData method based on the class's version
* information. This method does not write information about the class of the object. When
* deserializing use the method invokeFromData to read the contents of the object.
*
* @param ds the object to write
* @param out the output stream.
*/
public static void invokeToData(Object ds, DataOutput out) throws IOException {
boolean isDSFID = ds instanceof DataSerializableFixedID;
try {
boolean invoked = false;
Version v = InternalDataSerializer.getVersionForDataStreamOrNull(out);
if (v != null && v != Version.CURRENT) {
// get versions where DataOutput was upgraded
Version[] versions = null;
if (ds instanceof SerializationVersions) {
SerializationVersions sv = (SerializationVersions) ds;
versions = sv.getSerializationVersions();
}
// there has been a change in the message
if (versions != null && versions.length > 0) {
for (Version version : versions) {
// if peer version is less than the greatest upgraded version
if (v.compareTo(version) < 0) {
ds.getClass().getMethod("toDataPre_" + version.getMethodSuffix(), new Class[] { DataOutput.class }).invoke(ds, out);
invoked = true;
break;
}
}
}
}
if (!invoked) {
if (isDSFID) {
((DataSerializableFixedID) ds).toData(out);
} else {
((DataSerializable) ds).toData(out);
}
}
} catch (IOException io) {
// as a problem with the plugin code
if (isDSFID) {
throw io;
} else {
throw new ToDataException("toData failed on DataSerializable " + ds.getClass(), io);
}
} catch (CancelException | ToDataException | GemFireRethrowable ex) {
// Serializing a PDX can result in a cache closed exception. Just rethrow
throw ex;
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
throw new ToDataException("toData failed on DataSerializable " + ds.getClass(), t);
}
}
use of org.apache.geode.ToDataException in project geode by apache.
the class PdxAttributesJUnitTest method testLazyLoner.
/**
* Test that loner VMs lazily determine if they are a client or a peer.
*
* @throws Exception
*/
@Test
public void testLazyLoner() throws Exception {
// Test that we can become a peer registry
{
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
Cache cache = cf.create();
// This should work, because this is a peer.
defineAType();
}
tearDown();
setUp();
// Test that we can become a client registry.
{
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
Cache cache = cf.create();
int port = AvailablePortHelper.getRandomAvailableTCPPort();
PoolManager.createFactory().addServer("localhost", port).create("pool");
try {
defineAType();
throw new RuntimeException("Should have failed, this is a client that can't connect to a server");
} catch (ToDataException expected) {
// do nothing.
}
}
}
Aggregations