On Tue, Nov 18, 2008 at 3:14 AM, Toralf Wittner <[EMAIL PROTECTED]>wrote:

> On Sun, 2008-11-16 at 01:35 +0100, [EMAIL PROTECTED] wrote:
> > Currently agent errors are only reported when the agent is derefenced
> > or further actions are dispatched to the agent. It would be great if
> > one can get immediate notification of agent errors maybe through a
> > callback.
>
> I also have a need for early error reporting in case of agent errors, so
> I changed Agent.java to optionally take an addition error handler
> function that will be used as a callback as soon as exceptions occur.
> For example:
>
> user=> (def agt (agent 0))
> #'user/agt
> user=> (defn trouble [_] (throw (new Exception "Trouble")))
> #'user/trouble
> user=> (send agt trouble)
> #<Agent [EMAIL PROTECTED]>
> user=> @agt
> java.lang.Exception: Agent has errors (NO_SOURCE_FILE:0)
> user=> (clear-agent-errors agt)
> nil
> user=> @agt
> 0
> user=> (set-errorhandler agt (fn [a e] (.printStackTrace e)
> (clear-agent-errors a)))
> nil
> user=> (send agt trouble)
> java.lang.Exception: Trouble
>        at user$trouble__2.invoke(Unknown Source)
>        at clojure.lang.AFn.applyToHelper(AFn.java:193)
>        at clojure.lang.AFn.applyTo(AFn.java:184)
>        at clojure.lang.Agent$Action.doRun(Agent.java:72)
>        at clojure.lang.Agent$Action.run(Agent.java:117)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>        at java.lang.Thread.run(Thread.java:619)
> #<Agent [EMAIL PROTECTED]>
> user=> @agt
> 0
> user=> (def agt (agent 0 :error-fn (fn [a e] (.printStackTrace e)
> (clear-agent-errors a))))
> #'user/agt
> #'user/agt
> user=> (send agt trouble)
> java.lang.Exception: Trouble
>        at user$trouble__2.invoke(Unknown Source)
>        at clojure.lang.AFn.applyToHelper(AFn.java:193)
>        at clojure.lang.AFn.applyTo(AFn.java:184)
>        at clojure.lang.Agent$Action.doRun(Agent.java:72)
>        at clojure.lang.Agent$Action.run(Agent.java:117)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>        at java.lang.Thread.run(Thread.java:619)
> #<Agent [EMAIL PROTECTED]>
> user=> @agt
> 0
>
>
> The agent function is now keyword based and accepts :error-fn
> and/or :validate-fn. Alternatively error handlers can be set on an agent
> later. Since the change of the agent function is breaking existing code
> it is probably not what you (or Rich) want to have. Overloading it to
> take 3 parameters might be the better way.
>
> Anyway I second your request and would love to see some error reporting
> functionality in agents, as this really helped me a couple of times.
>
> Cheers,
> Toralf
>
>
I'm definitely interested in more centralized agent error handling, but I
don't want to jump into the per-agent error handler thing just yet.

At some point I'm probably going to provide abstractions over some of the
java.util.concurrent workflow stuff like queues and latches (since so few
people know they are there or how to use them). Then there might be a
default queue for agent errors, with the possibility of connecting an agent
to a specific error queue.

Rich

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to