Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

  • The SimpleServerGBean refers to another GBean EchoMessageInterface, which is described in Referencing another GBean.
  • The Plain Old Java Object (POJO) code comes with a different constructor annotated with @ParamSpecial, @ParamAttribute or @ParamReference.
  • There is no difference between the LifeCycle code implemented with and without annotations.
  • As the Geronimo kernel will recognize and invoke the attributes, operations, references and constructors defined with annotations, we have removed GBeanInfo implementation.
    Code Block
    java
    java
    titleSimpleServerGBeanjava
    public class SimpleServerGBean implements GBeanLifecycle, InterfaceNamed {
        private final String gbeanName;
        private EchoMessageInterface echo;
        private int port;
    
        private boolean started = false;
        private ServerSocket serversocket;
    
       /* Different contructor */ 
       public SimpleServerGBean(@ParamAttribute(name = "gbeanName") String gbeanName, 
    			    @ParamAttribute(name = "port") int port,
    			    @ParamReference(name = "EchoMessageInterface") EchoMessageInterface echomsg){
    			                 
            this.gbeanName = gbeanName;
    	this.port = port;
    	this.echo= echomsg;
        }
    
        public String getName() {
            return this.gbeanName;
        }
    
        public boolean isStarted() {
            return started;
        }
    
        private void printConsoleLog(String log) {
            System.out.println(" LOG : " + log);
        }
    
    
        public void doFail() {
            started = false;
            printConsoleLog("GBean " + gbeanName + " failed");
        }
    
        public void doStart() throws Exception {
    
    	 serversocket = new ServerSocket(port);
    	 started = true;
    
    	 Thread simpleServerThread = new Thread(new Runnable() {
    
    	 Socket socket;
    	 InputStream is;
    	 OutputStream os;
    
    	 public void run() {
    
    	     while (started) {
    		 try {
    	             socket = serversocket.accept();
    		     is = socket.getInputStream();
    		     os = socket.getOutputStream();
    
    		     BufferedReader bufferedReader = new BufferedReader(
    		     new InputStreamReader(is));
    
    		     String appendMessage=echo.getEchoMessage();
    		     String responseMessage = appendMessage + bufferedReader.readLine();
    
    		     os.write(responseMessage.getBytes());
    
    		     bufferedReader.close();
    		     if (os != null) {
    		         os.close();
    		     }
    			
                         if (socket != null && !socket.isClosed()) {
    			 socket.close();
    		     }
    
    		 } catch (Exception e) {
    
    		     //ingore
    
    		    }
    	       }
    
    	 }
    
        });
    
         simpleServerThread.start();
    
         printConsoleLog("GBean " + gbeanName
    				+ " started and it's listening on port:" + port);
    
         }
    
         public void doStop() throws Exception {
    
    	 started = false;
    	 serversocket.close();
    	 printConsoleLog("GBean " + gbeanName + " stopped");
         }
    
    }
    

The dployment plan for SimpleServerGBean has to be modified.

Code Block
xml
xml
titleExcerpt from simpleServer_deployment_plan.xmlxml
<gbean name="echoserver" class="org.apache.geronimo.sample.SimpleServerGBean">
    <attribute name="port">7777</attribute>
    <attribute name="gbeanName">simpleServer</attribute>
    <reference name="EchoMessageInterface">
        <name>msgAppender</name>
    </reference>
</gbean>
	
<gbean name="msgAppender" class="org.apache.geronimo.sample.EchoMessageGBean">
    <attribute name="msg">[Echo from server 1]:</attribute>
</gbean>

...