本文整理汇总了Java中net.jini.core.transaction.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于net.jini.core.transaction包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putAndUnlock
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
/**
* Unlocks the given key and puts the given value in a single operation.
*
* @param key The key to unlock and put the value in
* @param value The value to put after unlocking the key
*/
public void putAndUnlock(Object key, Object value) {
String uid = String.valueOf(key);
Transaction tr = lockedUIDHashMap.get(uid);
if (tr == null) {
map.put(key, value, null, Integer.MAX_VALUE);
return;
}
try {
map.put(key, value, tr, Integer.MAX_VALUE);
tr.commit();
} catch (Throwable t) {
logger.warn("Failed to commit transaction and unlock the key [" + key + "], ignoring", t);
} finally {
lockedUIDHashMap.remove(uid);
}
}
示例2: unlock
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
/**
* Unlocks the given lock on the key
*
* @param key The key to unlock
*/
public void unlock(Object key) {
String uid = String.valueOf(key);
Transaction tr = lockedUIDHashMap.get(uid);
if (tr == null) {
return;
}
try {
tr.commit();
} catch (Exception e) {
logger.warn("Failed to commit transaction and unlocking the object, ignoring", e);
} finally {
lockedUIDHashMap.remove(uid);
}
}
示例3: append
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public int append(Object obj, Transaction txn) throws RemoteException,
TransactionException, UnusableEntryException, InterruptedException {
End template = new End();
template.name = name;
End end = (End) space.take(template, txn, 250);
if (end != null) {
int position = end.increment();
space.write(end, txn, Lease.FOREVER);
Element element = new Element(name, position, obj);
space.write(element, txn, Lease.FOREVER);
return position;
}
return -1;
}
示例4: delete
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public boolean delete(Transaction txn, boolean force)
throws RemoteException, TransactionException,
UnusableEntryException, UnusableEntriesException,
InterruptedException {
if ((this.size(txn) > 0) && (!force))
return false;
else {
this.takeElements(txn, 500, Integer.MAX_VALUE);
Start startTemplate = new Start();
startTemplate.name = name;
End endTemplate = new End();
endTemplate.name = name;
Start starte = (Start) space.takeIfExists(startTemplate, txn,
Long.MAX_VALUE);
End ende = (End) space.takeIfExists(endTemplate, txn,
Long.MAX_VALUE);
return true;
}
}
示例5: exert
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Exertion exert(Transaction txn, Arg... entries)
throws TransactionException, MogramException, RemoteException {
try {
substitute(entries);
} catch (SetterException e) {
logger.error("Error in exertion {}", mogramId, e);
throw new MogramException(e);
}
String prvName = null;
for(Arg arg : entries) {
if (arg instanceof ProviderName) {
prvName = arg.getName();
break;
}
}
ServiceShell se = new ServiceShell(this);
return se.exert(txn, prvName, entries);
}
示例6: doJob
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Job doJob(Transaction txn) throws ExertionException,
SignatureException, RemoteException {
// return (Job) new ServiceJobber().exec(job, txn);
Job result = null;
try {
ObjectSignature os = (ObjectSignature) getProcessSignature();
Evaluator evaluator = ((ObjectSignature) getProcessSignature())
.getEvaluator();
if (evaluator == null) {
evaluator = new MethodInvoker(os.newInstance(),
os.getSelector());
}
evaluator.setParameterTypes(new Class[] { Mogram.class });
evaluator.setParameters(new Object[] { this });
result = (Job)evaluator.evaluate();
getControlContext().appendTrace("job by: " + evaluator.getClass().getName());
} catch (Exception e) {
e.printStackTrace();
if (controlContext != null)
controlContext.addException(e);
}
return result;
}
示例7: doBlock
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Block doBlock(Transaction txn, Arg... args) throws ExertionException,
SignatureException, RemoteException {
// return (Job) new ServiceJobber().exec(job, txn);
Block result = null;
try {
ObjectSignature os = (ObjectSignature) getProcessSignature();
Evaluator evaluator = ((ObjectSignature) getProcessSignature())
.getEvaluator();
if (evaluator == null) {
evaluator = new MethodInvoker(os.newInstance(),
os.getSelector());
}
evaluator.setParameterTypes(new Class[] { Mogram.class });
evaluator.setParameters(new Object[] { this });
result = (Block)evaluator.evaluate(args);
getControlContext().appendTrace("block by: " + evaluator.getClass().getName());
} catch (Exception e) {
e.printStackTrace();
if (controlContext != null)
controlContext.addException(e);
}
return result;
}
示例8: exert
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
@Override
public <T extends Mogram> T exert(Transaction txn, Arg... entries) throws TransactionException,
ExertionException, RemoteException {
Signature signature = null;
try {
if (subjectValue instanceof Class) {
signature = sig(subjectPath, subjectValue);
return (T) ((Exertion)operator.xrt(name, signature, this).exert(txn, entries)).getContext();
} else {
// evaluates model outputs - response
getResponse(entries);
return (T) this;
}
} catch (Exception e) {
throw new ExertionException(e);
}
}
示例9: exert
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Context exert(Mogram mogram, Transaction txn, Arg... args)
throws TransactionException, MogramException, RemoteException {
Context cxt = null;
if (mogram instanceof Context) {
cxt = (Context)mogram;
} else {
cxt = context(exert(mogram, txn, args));
}
Task out = null;
out = task(this, cxt);
Object result = exert(out);
if (result instanceof Context)
return (Context)result;
else
return exert(out).getContext();
}
示例10: exert
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Context exert(Mogram mogram, Transaction txn) throws TransactionException,
MogramException, RemoteException {
Context cxt = null;
ObjectTask task = null;
if (mogram instanceof Context)
cxt = (Context)mogram;
else
cxt = context(mogram.exert());
try {
task = new ObjectTask(this, cxt);
} catch (SignatureException e) {
throw new MogramException(e);
}
return task.exert(txn).getContext();
}
示例11: doCompound
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Mogram doCompound(Mogram mogram, Transaction txn, Arg... args)
throws TransactionException, ExertionException, RemoteException {
setServiceID(mogram);
try {
MogramThread mogramThread = new MogramThread(mogram, provider, getDispatcherFactory((Exertion)mogram));
if (((Exertion)mogram).getControlContext().isMonitorable()
&& !((Exertion)mogram).getControlContext().isWaitable()) {
replaceNullExertionIDs((Exertion)mogram);
notifyViaEmail((Exertion)mogram);
new Thread(mogramThread, ((Job)mogram).getContextName()).start();
return mogram;
} else {
mogramThread.run();
Mogram result = mogramThread.getResult();
logger.debug("<== Result: " + result);
return result;
}
} catch (Exception e) {
((ServiceExertion)mogram).reportException(e);
logger.warn("Error: " + e.getMessage());
return mogram;
}
}
示例12: exert
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Mogram exert(Mogram mogram, Transaction transaction, Arg... args) throws RemoteException, ExertionException {
Mogram out = null;
try {
setServiceID(mogram);
mogram.appendTrace("mogram: " + mogram.getName() + " rendezvous: " +
(provider != null ? provider.getProviderName() + " " : "")
+ this.getClass().getName());
if (mogram instanceof ObjectJob || mogram instanceof ObjectBlock
|| mogram instanceof Model || mogram instanceof ModelingTask) {
logger.info("{} is a local exertion", mogram.getName());
out = localExert(mogram, transaction, args);
} else {
logger.info("{} is a remote exertion", mogram.getName());
out = getControlFlownManager(mogram).process();
}
if (mogram instanceof Exertion)
mogram.getDataContext().setExertion(null);
}
catch (Exception e) {
logger.debug("exert failed for: " + mogram.getName(), e);
throw new ExertionException();
}
return out;
}
示例13: localExert
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Mogram localExert(Mogram mogram, Transaction txn, Arg... args)
throws TransactionException, ExertionException, RemoteException {
setServiceID(mogram);
try {
MogramThread mogramThread = new MogramThread(mogram, provider, getDispatcherFactory((Exertion)mogram));
if (((Exertion)mogram).getControlContext().isMonitorable()
&& !((Exertion)mogram).getControlContext().isWaitable()) {
replaceNullExertionIDs((Exertion)mogram);
notifyViaEmail((Exertion)mogram);
new Thread(mogramThread, ((Job)mogram).getContextName()).start();
return mogram;
} else {
mogramThread.run();
Mogram result = mogramThread.getResult();
logger.debug("<== Result: " + result);
return result;
}
} catch (Exception e) {
e.printStackTrace();
mogram.reportException(e);
logger.warn("Error: " + e.getMessage());
return mogram;
}
}
示例14: localExert
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
public Mogram localExert(Mogram mogram, Transaction txn, Arg... args)
throws TransactionException, ExertionException, RemoteException {
Exertion exertion = (Exertion) mogram;
setServiceID(exertion);
Block result;
try {
if (((ServiceExertion)exertion).getControlContext().isMonitorable()
&& !(((ServiceExertion)exertion).getControlContext()).isWaitable()) {
replaceNullExertionIDs(exertion);
new BlockThread((Block) exertion, provider).start();
return exertion;
} else {
BlockThread blockThread = new BlockThread((Block) exertion, provider, args);
blockThread.start();
blockThread.join();
result = blockThread.getResult();
Condition.cleanupScripts(result);
logger.trace("<==== Result: " + result);
}
} catch (Throwable e) {
logger.error("Failed exerting {}", mogram.getName(), e);
throw new ExertionException(e);
}
return result;
}
示例15: doExertion
import net.jini.core.transaction.Transaction; //导入依赖的package包/类
/**
* This method calls on an ExertionProcessor which executes the exertion
* accordingly to its compositional type.
*
* @param exertion
* Exertion
* @return Exertion
* @throws sorcer.service.ExertionException
* @see sorcer.service.Exertion
* @see sorcer.service.Conditional
* @see sorcer.core.provider.ControlFlowManager
* @throws java.rmi.RemoteException
* @throws sorcer.service.ExertionException
*/
public Exertion doExertion(final Exertion exertion, Transaction txn) throws ExertionException {
logger.debug("service: {}", exertion.getName());
// create an instance of the ControlFlowManager and call on the
// process method, returns an Exertion
Exertion out;
try {
if(delegate.isRemoteLogging()) {
MDC.put(MDC_SORCER_REMOTE_CALL, MDC_SORCER_REMOTE_CALL);
MDC.put(MDC_PROVIDER_ID, this.getId().toString());
MDC.put(MDC_PROVIDER_NAME, this.getName());
}
if (exertion.getId() != null)
MDC.put(MDC_MOGRAM_ID, exertion.getId().toString());
out = (Exertion) getControlFlownManager(exertion).process();
} finally {
MDC.remove(MDC_PROVIDER_NAME);
MDC.remove(MDC_SORCER_REMOTE_CALL);
MDC.remove(MDC_MOGRAM_ID);
MDC.remove(MDC_PROVIDER_ID);
}
return out;
}