hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hivemind-...@jakarta.apache.org
Subject [Jakarta HiveMind Wiki] Updated: Examples
Date Fri, 04 Jun 2004 20:13:34 GMT
   Date: 2004-06-04T13:13:34
   Editor: SteveGibson <steve.sgibon@cowww.com>
   Wiki: Jakarta HiveMind Wiki
   Page: Examples
   URL: http://wiki.apache.org/jakarta-hivemind/Examples

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -2,3 +2,40 @@
 What would be nice to have is for example:
   * How to fetch java.sql.Connection using hivemind service.
   * More interceptor docs?
+
+The cool thing about HiveMind is that using services is no more complex than the simple calculator
example.
+(Oh wow, I just realized the example is a whole calculator now, not just an Adder!)
+Configuration schema examples are something that would probably be more beneficial.
+
+As for the interceptor - here is an ugly example of an interceptor for the Divider (off the
top of my head:
+
+public class DividerInterceptor extends AbstractServiceInterceptorFactory
+{
+   protected void addServiceMethodImplementation(
+      ClassFab classFab,
+      String methodName,
+      Class returnType,
+      Class[] parameterTypes,
+      Class[] exceptionTypes)
+   {
+      if (methodName.equals("divide"))
+      {
+         BodyBuilder builder = new BodyBuilder();
+
+         builder.begin();
+         builder.addln("if ($1 == 0)"); 
+         builder.addln("{");
+         builder.addln("throw new ArithmeticException(\"Division by zero\");");
+         builder.addln("}");
+         builder.addln("return ($r) _inner." + methodName + "($$);" );
+         builder.end();
+         classFab.addMethod(Modifier.PUBLIC,
+             methodName,
+             returnType,
+             parameterTypes,
+             exceptionTypes,
+             builder.toString()
+         );
+        }
+     }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message