Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete examples 11930 #2047

Merged
merged 7 commits into from
Feb 4, 2014
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 26 additions & 21 deletions examples/Delete/FileAnnotationDelete.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import omero.LockTimeout;
import omero.ServerError;
import omero.api.IDeletePrx;
import omero.cmd.Delete;
import omero.cmd.DoAll;
import omero.cmd.Request;
import omero.cmd.OK;
import omero.cmd.CmdCallbackI;
import omero.cmd.Response;
import omero.api.ServiceFactoryPrx;
import omero.api.delete.DeleteCommand;
import omero.api.delete.DeleteHandlePrx;
import omero.api.delete.DeleteReport;
import omero.grid.DeleteCallbackI;
import omero.model.*;
import static omero.rtypes.*;
import Glacier2.CannotCreateSessionException;
import Glacier2.PermissionDeniedException;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

/**
* Uses the default {@link DeleteCallbackI} instance
* to delete a FileAnnotation along with its associated
Expand All @@ -37,28 +44,26 @@ public static void main(String[] args) throws CannotCreateSessionException,
fa = (FileAnnotation) d.linkedAnnotationList().get(0);


IDeletePrx deleteServicePrx = s.getDeleteService();
DeleteCommand dc = new DeleteCommand("/Annotation", fa.getId().getValue(), null);
DeleteHandlePrx deleteHandlePrx = deleteServicePrx
.queueDelete(new DeleteCommand[] { dc });
DeleteCallbackI cb = new DeleteCallbackI(c, deleteHandlePrx);
Delete dc = new Delete("/Annotation", fa.getId().getValue(), null);
List<Request> commands = new ArrayList<Request>();
commands.add(dc);
DoAll all = new DoAll();
all.requests = commands;
Map<String, String> callContext = new HashMap<String, String>();
CmdCallbackI cb = null;
try {

cb = new CmdCallbackI(c, s.submit(all, callContext));
cb.loop(10, 500);

DeleteReport[] reports = deleteHandlePrx.report();
DeleteReport r = reports[0]; // We only sent one command
System.out.println(String.format(
"Report:error=%s,warning=%s,deleted=%s", r.error,
r.warning, r.actualDeletes));

} catch (LockTimeout lt) {
Response rsp = cb.getResponse();
if (rsp instanceof OK) {
System.out.println("OK");
}
} catch (InterruptedException lt) {
System.out.println("Not finished in 5 seconds. Cancelling...");
if (!deleteHandlePrx.cancel()) {
if (!cb.isCancelled())
System.out.println("ERROR: Failed to cancel");
}
} finally {
cb.close();
if (cb != null) cb.close(true);
}

} finally {
Expand Down
49 changes: 23 additions & 26 deletions examples/Delete/FileAnnotationDelete.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,31 @@
s = c.createSession()
d = DatasetI()
d.setName(rstring("FileAnnotationDelete"))
fa = FileAnnotationI()
file = c.upload(ice_config)
fa.setFile(file)
d.linkAnnotation(fa)
d = s.getUpdateService().saveAndReturnObject(d)
fa = d.linkedAnnotationList()[0]

deleteServicePrx = s.getDeleteService();
dc = omero.api.delete.DeleteCommand("/Annotation", fa.id.val, None)
deleteHandlePrx = deleteServicePrx .queueDelete([dc])
cb = omero.callbacks.DeleteCallbackI(c, deleteHandlePrx)

try:

try:
cb.loop(10, 500)
except omero.LockTimeout:
print "Not finished in 5 seconds. Cancelling..."
if not deleteHandlePrx.cancel():
print "ERROR: Failed to cancel"

reports = deleteHandlePrx.report()
r = reports[0] # We only sent one command
print "Report:error=%s,warning=%s,deleted=%s" % \
(r.error, r.warning, r.actualDeletes)

finally:
cb.close()
file = c.upload(ice_config)
fa = FileAnnotationI()
fa.setFile(OriginalFileI(file.id.val, False))
link = DatasetAnnotationLinkI()
link.parent = DatasetI(d.id.val, False)
link.child = fa
link = s.getUpdateService().saveAndReturnObject(link)
fa = link.child

graph_spec = "/Annotation"
options = {}
delCmd = omero.cmd.Delete(graph_spec, long(fa.id.val), options)

dcs = [delCmd]
doall = omero.cmd.DoAll()
doall.requests = dcs
handle = s.submit(doall)

callback = omero.callbacks.CmdCallbackI(c, handle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback is not closed in a finally which will lead to resource exhaustion.

loops = 10
delay = 500
callback.loop(loops, delay) # Throw LockTimeout
rsp = callback.getResponse()

finally:
c.closeSession()