00001 /* 00002 * Comedian example code to demonstrate CAST functionality. 00003 * 00004 * Copyright (C) 2006-2007 Nick Hawes 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation; either version 2.1 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 * 02110-1301 USA 00020 * 00021 */ 00022 00026 package comedyarch; 00027 00028 import cast.AlreadyExistsOnWMException; 00029 import cast.architecture.UnmanagedComponent; 00030 import cast.core.CASTUtils; 00031 00032 import comedyarch.autogen.TwoLiner; 00033 00037 public class StraightMan extends UnmanagedComponent { 00038 00039 private String generateSetup() { 00040 return "What's brown and sticky?"; 00041 } 00042 00043 @Override 00044 public void runComponent() { 00045 while (isRunning()) { 00046 00047 try { 00048 // must check we're still running after sleep! 00049 if (isRunning()) { 00050 00051 // lock from external access 00052 lockComponent(); 00053 00054 println("ahem..."); 00055 println(CASTUtils.toString(getCASTTime())); 00056 00057 // make up a joke 00058 TwoLiner jk = new TwoLiner("", generateSetup()); 00059 00060 // and then make it available in the s-a working 00061 // memory 00062 addToWorkingMemory(newDataID(), jk); 00063 // addToWorkingMemory(newDataID(), "audience.sa", jk); 00064 // let other stuff happen if necessary 00065 unlockComponent(); 00066 00067 sleepComponent(1); 00068 } 00069 } catch (AlreadyExistsOnWMException e) { 00070 e.printStackTrace(); 00071 } 00072 // catch (UnknownSubarchitectureException e) { 00073 // e.printStackTrace(); 00074 // } 00075 00076 } 00077 00078 } 00079 00080 }
1.5.8