use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class GridServiceProcessor method prepareServiceConfigurations.
/**
* @param cfgs Service configurations.
* @param dfltNodeFilter Default NodeFilter.
* @return Configurations to deploy.
*/
private PreparedConfigurations prepareServiceConfigurations(Collection<ServiceConfiguration> cfgs, IgnitePredicate<ClusterNode> dfltNodeFilter) {
List<ServiceConfiguration> cfgsCp = new ArrayList<>(cfgs.size());
Marshaller marsh = ctx.config().getMarshaller();
List<GridServiceDeploymentFuture> failedFuts = null;
for (ServiceConfiguration cfg : cfgs) {
Exception err = null;
// or only on server nodes if no projection .
if (cfg.getNodeFilter() == null && dfltNodeFilter != null)
cfg.setNodeFilter(dfltNodeFilter);
try {
validate(cfg);
} catch (Exception e) {
U.error(log, "Failed to validate service configuration [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ']', e);
err = e;
}
if (err == null) {
try {
ctx.security().authorize(cfg.getName(), SecurityPermission.SERVICE_DEPLOY, null);
} catch (Exception e) {
U.error(log, "Failed to authorize service creation [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ']', e);
err = e;
}
}
if (err == null) {
try {
byte[] srvcBytes = U.marshal(marsh, cfg.getService());
cfgsCp.add(new LazyServiceConfiguration(cfg, srvcBytes));
} catch (Exception e) {
U.error(log, "Failed to marshal service with configured marshaller [name=" + cfg.getName() + ", srvc=" + cfg.getService() + ", marsh=" + marsh + "]", e);
err = e;
}
}
if (err != null) {
if (failedFuts == null)
failedFuts = new ArrayList<>();
GridServiceDeploymentFuture fut = new GridServiceDeploymentFuture(cfg);
fut.onDone(err);
failedFuts.add(fut);
}
}
return new PreparedConfigurations(cfgsCp, failedFuts);
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class GridServiceProcessor method copyAndInject.
/**
* @param cfg Service configuration.
* @return Copy of service.
* @throws IgniteCheckedException If failed.
*/
private Service copyAndInject(ServiceConfiguration cfg) throws IgniteCheckedException {
Marshaller m = ctx.config().getMarshaller();
if (cfg instanceof LazyServiceConfiguration) {
byte[] bytes = ((LazyServiceConfiguration) cfg).serviceBytes();
Service srvc = U.unmarshal(m, bytes, U.resolveClassLoader(null, ctx.config()));
ctx.resource().inject(srvc);
return srvc;
} else {
Service svc = cfg.getService();
try {
byte[] bytes = U.marshal(m, svc);
Service cp = U.unmarshal(m, bytes, U.resolveClassLoader(svc.getClass().getClassLoader(), ctx.config()));
ctx.resource().inject(cp);
return cp;
} catch (IgniteCheckedException e) {
U.error(log, "Failed to copy service (will reuse same instance): " + svc.getClass(), e);
return svc;
}
}
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class GridSessionCheckpointAbstractSelfTest method checkFinishedState.
/**
* @param sesKey Session key.
* @param globalKey Global key.
* @param globalState Global state.
* @throws Exception If check failed.
*/
private void checkFinishedState(String sesKey, String globalKey, String globalState) throws Exception {
byte[] serState = spi.loadCheckpoint(sesKey);
assert serState == null : "Session scope variable is not null: " + Arrays.toString(serState);
serState = spi.loadCheckpoint(globalKey);
Marshaller marshaller = IgniteTestResources.getMarshaller();
assert marshaller != null;
String state = marshaller.unmarshal(serState, getClass().getClassLoader());
assert state != null : "Global state is missing: " + globalKey;
assert state.equals(globalState) : "Invalid state value: " + state;
spi.removeCheckpoint(globalKey);
Object cp = spi.loadCheckpoint(globalKey);
assert cp == null;
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class GridCacheQueryResponse method unmarshalCollection0.
/**
* @param byteCol Collection to unmarshal.
* @param ctx Context.
* @param ldr Loader.
* @return Unmarshalled collection.
* @throws IgniteCheckedException If failed.
*/
@Nullable
protected <T> List<T> unmarshalCollection0(@Nullable Collection<byte[]> byteCol, GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
assert ldr != null;
assert ctx != null;
if (byteCol == null)
return null;
List<T> col = new ArrayList<>(byteCol.size());
Marshaller marsh = ctx.marshaller();
ClassLoader ldr0 = U.resolveClassLoader(ldr, ctx.gridConfig());
CacheObjectContext cacheObjCtx = null;
for (byte[] bytes : byteCol) {
Object obj = bytes == null ? null : marsh.<T>unmarshal(bytes, ldr0);
if (obj instanceof Map.Entry) {
Object key = ((Map.Entry) obj).getKey();
if (key instanceof KeyCacheObject) {
if (cacheObjCtx == null)
cacheObjCtx = ctx.cacheContext(cacheId).cacheObjectContext();
((KeyCacheObject) key).finishUnmarshal(cacheObjCtx, ldr0);
}
}
col.add((T) obj);
}
return col;
}
use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.
the class GridCacheVersionSelfTest method testMarshalling.
/**
* Test versions marshalling.
*
* @throws Exception If failed.
*/
public void testMarshalling() throws Exception {
GridCacheVersion ver = version(1, 1);
GridCacheVersionEx verEx = new GridCacheVersionEx(2, 2, 0, ver);
Marshaller marsh = createStandaloneBinaryMarshaller();
byte[] verBytes = marsh.marshal(ver);
byte[] verExBytes = marsh.marshal(verEx);
GridCacheVersion verNew = marsh.unmarshal(verBytes, Thread.currentThread().getContextClassLoader());
GridCacheVersionEx verExNew = marsh.unmarshal(verExBytes, Thread.currentThread().getContextClassLoader());
assert ver.equals(verNew);
assert verEx.equals(verExNew);
}
Aggregations