use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class PlatformCppConfigurationClosure method apply0.
/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@Override
protected void apply0(IgniteConfiguration igniteCfg) {
// 3. Validate and copy Interop configuration setting environment pointer along the way.
PlatformConfiguration interopCfg = igniteCfg.getPlatformConfiguration();
if (interopCfg != null && !(interopCfg instanceof PlatformCppConfiguration))
throw new IgniteException("Illegal interop configuration (must be of type " + PlatformCppConfiguration.class.getName() + "): " + interopCfg.getClass().getName());
PlatformCppConfiguration cppCfg = interopCfg != null ? (PlatformCppConfiguration) interopCfg : null;
if (cppCfg == null)
cppCfg = new PlatformCppConfiguration();
PlatformMemoryManagerImpl memMgr = new PlatformMemoryManagerImpl(gate, 1024);
PlatformCppConfigurationEx cppCfg0 = new PlatformCppConfigurationEx(cppCfg, gate, memMgr);
igniteCfg.setPlatformConfiguration(cppCfg0);
// Check marshaller
Marshaller marsh = igniteCfg.getMarshaller();
if (marsh == null) {
igniteCfg.setMarshaller(new BinaryMarshaller());
cppCfg0.warnings(Collections.singleton("Marshaller is automatically set to " + BinaryMarshaller.class.getName() + " (other nodes must have the same marshaller type)."));
} else if (!(marsh instanceof BinaryMarshaller))
throw new IgniteException("Unsupported marshaller (only " + BinaryMarshaller.class.getName() + " can be used when running Apache Ignite C++): " + marsh.getClass().getName());
BinaryConfiguration bCfg = igniteCfg.getBinaryConfiguration();
if (bCfg == null) {
bCfg = new BinaryConfiguration();
bCfg.setCompactFooter(false);
bCfg.setNameMapper(new BinaryBasicNameMapper(true));
bCfg.setIdMapper(new BinaryBasicIdMapper(true));
igniteCfg.setBinaryConfiguration(bCfg);
cppCfg0.warnings(Collections.singleton("Binary configuration is automatically initiated, " + "note that binary name mapper is set to " + bCfg.getNameMapper() + " and binary ID mapper is set to " + bCfg.getIdMapper() + " (other nodes must have the same binary name and ID mapper types)."));
} else {
BinaryNameMapper nameMapper = bCfg.getNameMapper();
if (nameMapper == null) {
bCfg.setNameMapper(new BinaryBasicNameMapper(true));
cppCfg0.warnings(Collections.singleton("Binary name mapper is automatically set to " + bCfg.getNameMapper() + " (other nodes must have the same binary name mapper type)."));
}
BinaryIdMapper idMapper = bCfg.getIdMapper();
if (idMapper == null) {
bCfg.setIdMapper(new BinaryBasicIdMapper(true));
cppCfg0.warnings(Collections.singleton("Binary ID mapper is automatically set to " + bCfg.getIdMapper() + " (other nodes must have the same binary ID mapper type)."));
}
}
if (bCfg.isCompactFooter())
throw new IgniteException("Unsupported " + BinaryMarshaller.class.getName() + " \"compactFooter\" flag: must be false when running Apache Ignite C++.");
// Set Ignite home so that marshaller context works.
String ggHome = igniteCfg.getIgniteHome();
if (ggHome != null)
U.setIgniteHome(ggHome);
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class PlatformDotNetConfigurationClosure method setBinaryConfiguration.
/**
* Sets binary config.
*
* @param igniteCfg Ignite config.
* @param dotNetCfg .NET config.
*/
private void setBinaryConfiguration(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx dotNetCfg) {
// Check marshaller.
Marshaller marsh = igniteCfg.getMarshaller();
if (marsh == null) {
igniteCfg.setMarshaller(new BinaryMarshaller());
dotNetCfg.warnings(Collections.singleton("Marshaller is automatically set to " + BinaryMarshaller.class.getName() + " (other nodes must have the same marshaller type)."));
} else if (!(marsh instanceof BinaryMarshaller))
throw new IgniteException("Unsupported marshaller (only " + BinaryMarshaller.class.getName() + " can be used when running Apache Ignite.NET): " + marsh.getClass().getName());
BinaryConfiguration bCfg = igniteCfg.getBinaryConfiguration();
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class HadoopExternalCommunicationSelfTest method checkSimpleMessageSending.
/**
* @throws Exception If failed.
*/
private void checkSimpleMessageSending(boolean useShmem) throws Exception {
UUID parentNodeId = UUID.randomUUID();
Marshaller marsh = new JdkMarshaller();
IgniteLogger log = log();
HadoopExternalCommunication[] comms = new HadoopExternalCommunication[4];
try {
String name = "grid";
TestHadoopListener[] lsnrs = new TestHadoopListener[4];
int msgs = 10;
for (int i = 0; i < comms.length; i++) {
comms[i] = new HadoopExternalCommunication(parentNodeId, UUID.randomUUID(), marsh, log, Executors.newFixedThreadPool(1), name + i, U.defaultWorkDirectory());
if (useShmem)
comms[i].setSharedMemoryPort(14000);
lsnrs[i] = new TestHadoopListener(msgs);
comms[i].setListener(lsnrs[i]);
comms[i].start();
}
for (int r = 0; r < msgs; r++) {
for (int from = 0; from < comms.length; from++) {
for (int to = 0; to < comms.length; to++) {
if (from == to)
continue;
comms[from].sendMessage(comms[to].localProcessDescriptor(), new TestMessage(from, to));
}
}
}
U.sleep(1000);
for (TestHadoopListener lsnr : lsnrs) {
lsnr.await(3_000);
assertEquals(String.valueOf(lsnr.messages()), msgs * (comms.length - 1), lsnr.messages().size());
}
} finally {
for (HadoopExternalCommunication comm : comms) {
if (comm != null)
comm.stop();
}
}
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class WebSessionSelfTest method testInvalidatedSession.
/**
* Tests invalidated sessions.
*
* @throws Exception Exception If failed.
*/
public void testInvalidatedSession() throws Exception {
String invalidatedSesId;
Server srv = null;
try {
srv = startServer(TEST_JETTY_PORT, "/modules/core/src/test/config/websession/example-cache.xml", null, new InvalidatedSessionServlet());
Ignite ignite = G.ignite();
URLConnection conn = new URL("http://localhost:" + TEST_JETTY_PORT + "/ignitetest/invalidated").openConnection();
conn.connect();
try (BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
// checks if the old session object is invalidated.
invalidatedSesId = rdr.readLine();
assertNotNull(invalidatedSesId);
if (!keepBinary()) {
IgniteCache<String, HttpSession> cache = ignite.cache(getCacheName());
assertNotNull(cache);
HttpSession invalidatedSes = cache.get(invalidatedSesId);
assertNull(invalidatedSes);
// requests to subsequent getSession() returns null.
String ses = rdr.readLine();
assertEquals("null", ses);
} else {
IgniteCache<String, WebSessionEntity> cache = ignite.cache(getCacheName());
assertNotNull(cache);
WebSessionEntity invalidatedSes = cache.get(invalidatedSesId);
assertNull(invalidatedSes);
// requests to subsequent getSession() returns null.
String ses = rdr.readLine();
assertEquals("null", ses);
}
}
// put and update.
final CountDownLatch latch = new CountDownLatch(2);
final IgnitePredicate<Event> putLsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt != null;
latch.countDown();
return true;
}
};
ignite.events().localListen(putLsnr, EVT_CACHE_OBJECT_PUT);
// new request that creates a new session.
conn = new URL("http://localhost:" + TEST_JETTY_PORT + "/ignitetest/valid").openConnection();
conn.addRequestProperty("Cookie", "JSESSIONID=" + invalidatedSesId);
conn.connect();
try (BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
String sesId = rdr.readLine();
assertFalse(sesId.equals("null"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
if (!keepBinary()) {
IgniteCache<String, HttpSession> cache = ignite.cache(getCacheName());
assertNotNull(cache);
HttpSession ses = cache.get(sesId);
assertNotNull(ses);
assertEquals("val10", ses.getAttribute("key10"));
} else {
IgniteCache<String, WebSessionEntity> cache = ignite.cache(getCacheName());
assertNotNull(cache);
WebSessionEntity entity = cache.get(sesId);
assertNotNull(entity);
final Marshaller marshaller = ignite.configuration().getMarshaller();
assertEquals("val10", marshaller.unmarshal(entity.attributes().get("key10"), getClass().getClassLoader()));
}
}
} finally {
stopServer(srv);
}
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class WebSessionSelfTest method testSessionRenewalDuringLogin.
/**
* Tests session renewal during login. Checks modification attribute in cache.
*
* @param cfg Configuration.
* @throws Exception If failed.
*/
private void testSessionRenewalDuringLogin(String cfg) throws Exception {
Server srv = null;
String sesId;
try {
srv = startServerWithLoginService(TEST_JETTY_PORT, cfg, null, new SessionLoginServlet());
URLConnection conn = new URL("http://localhost:" + TEST_JETTY_PORT + "/ignitetest/test").openConnection();
conn.connect();
String sesIdCookie1 = getSessionIdFromCookie(conn);
X.println(">>>", "Initial session Cookie: " + sesIdCookie1, ">>>");
try (BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
sesId = rdr.readLine();
if (!keepBinary()) {
IgniteCache<String, HttpSession> cache = G.ignite().cache(getCacheName());
assertNotNull(cache);
HttpSession ses = cache.get(sesId);
assertNotNull(ses);
assertEquals("val1", ses.getAttribute("key1"));
} else {
final IgniteCache<String, WebSessionEntity> cache = G.ignite().cache(getCacheName());
assertNotNull(cache);
final WebSessionEntity entity = cache.get(sesId);
assertNotNull(entity);
final byte[] data = entity.attributes().get("key1");
assertNotNull(data);
final Marshaller marshaller = G.ignite().configuration().getMarshaller();
final String val = marshaller.unmarshal(data, getClass().getClassLoader());
assertEquals("val1", val);
}
}
URLConnection conn2 = new URL("http://localhost:" + TEST_JETTY_PORT + "/ignitetest/login").openConnection();
HttpURLConnection con = (HttpURLConnection) conn2;
con.addRequestProperty("Cookie", "JSESSIONID=" + sesIdCookie1);
con.setRequestMethod("POST");
con.setDoOutput(true);
String sesIdCookie2 = getSessionIdFromCookie(con);
X.println(">>>", "Logged In session Cookie: " + sesIdCookie2, ">>>");
try (BufferedReader rdr = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
String sesId2 = rdr.readLine();
if (!keepBinary()) {
IgniteCache<String, HttpSession> cache = G.ignite().cache(getCacheName());
assertNotNull(cache);
HttpSession ses = cache.get(sesId2);
assertNotNull(ses);
assertEquals("val1", ses.getAttribute("key1"));
} else {
final IgniteCache<String, WebSessionEntity> cache = G.ignite().cache(getCacheName());
assertNotNull(cache);
final WebSessionEntity entity = cache.get(sesId2);
assertNotNull(entity);
final byte[] data = entity.attributes().get("key1");
assertNotNull(data);
final Marshaller marshaller = G.ignite().configuration().getMarshaller();
final String val = marshaller.unmarshal(data, getClass().getClassLoader());
assertEquals("val1", val);
}
}
URLConnection conn3 = new URL("http://localhost:" + TEST_JETTY_PORT + "/ignitetest/simple").openConnection();
conn3.addRequestProperty("Cookie", "JSESSIONID=" + sesIdCookie2);
conn3.connect();
String sesIdCookie3 = getSessionIdFromCookie(conn3);
X.println(">>>", "Post Logged In session Cookie: " + sesIdCookie3, ">>>");
assertEquals(sesIdCookie2, sesIdCookie3);
try (BufferedReader rdr = new BufferedReader(new InputStreamReader(conn3.getInputStream()))) {
String sesId3 = rdr.readLine();
if (!keepBinary()) {
IgniteCache<String, HttpSession> cache = G.ignite().cache(getCacheName());
HttpSession session = cache.get(sesId3);
assertNotNull(session);
assertNotNull(cache);
HttpSession ses = cache.get(sesId3);
assertNotNull(ses);
assertEquals("val1", ses.getAttribute("key1"));
} else {
final IgniteCache<String, WebSessionEntity> cache = G.ignite().cache(getCacheName());
assertNotNull(cache);
final WebSessionEntity entity = cache.get(sesId3);
assertNotNull(entity);
assertNotNull(cache.get(sesId3));
final byte[] data = entity.attributes().get("key1");
assertNotNull(data);
final Marshaller marshaller = G.ignite().configuration().getMarshaller();
final String val = marshaller.unmarshal(data, getClass().getClassLoader());
assertEquals("val1", val);
}
}
} finally {
stopServerWithLoginService(srv);
}
}
Aggregations