Open design
Home Forum News
Document
Download
  • Document
  • Source
  • Bindary
Project
  • Schema
  • Bug Trace
  • Mail List
Contact

Jmservice Framework

Chris Liao

2007/02/01

 

                 Content

1.   Introduction  

1.1.     What is service?

1.2.     Service and Client

1.3.     Service and Lifecycle

1.4.     Service and other Service

1.5.     Service and Domain

1.6.     Service and Component  

1.7.     Component and Description

1.8.     Source and Detection

1.9.     Source and Identification

1.10.     Source and Parser

1.11.   Component and Deployment  

2.   Framework (Jmservice)  

2.1. Objectives

2.2. Classes and Interfaces

2.2.1. API Source

2.2.2. Static Relationship

3.   Jmservice in J2EE server (Jmserver)

3.1.     Objectives

3.2.     What in J2EE Server?

3.3.     Characters of service

3.4.     Configuration of Service

3.4.1.1.   File format

3.4.1.2.   Order in the file

3.4.1.3.   Service List in Jmin

3.5.     Management of service

3.6.     How to launch service?

3.7.     How to discover j2ee source?(Jmdiscover)

3.8.     How to deploy components?

3.9.     Relationship between Jmservice,Jmserver,Jmdiscover

3.10.     Classes and Interfaces

3.10.1.  API Source

3.10.1.1. Source in Jmserver

3.10.1.2.   Source in Jmdiscover

3.10.2.      Static relationship in Jmserver

3.10.3.      Control flow in jmserver

4.   Jmservice in others

5.   About the author

1.   Introduction

Jmservice is a SOP(Service Oriented Programming)framework, which is contained in jmin server. The framework is designed to programming in logic domain. If you are not familiar with its theory and its basic concept; we will introduce them to you step by step and lead you over the course of our design.

1.1. What is service?

Why dose our program visit servers? It is because servers provide some useful applications to be visited and to handle request from clients. This phenomenon is very general in Client-Server model, maybe you enjoy or use some various applications in servers for your work, but you don't care their concept and  their internal actions. Although these applications look very complex and different, if be careful, a common feature can be found in overview: every one works in a domain and  makes effect to others, for example: handle invocation  from outside or finish  some useful tasks for outside.In our opinions, we suggest to use 'service' word to represent the feature. "Service" is a logic concept, some objects are integrated together to finish collaboration and should be regarded as one in logic point. It is that integration in logic and separation in physics for these objects. Sometimes, the "service" word doesn't appear in some applications, but in fact, same things are doing. Here, we abstract this concept further and define it as a object, you can get it from our source.

1.2. Service and Client

If exist some services to be visited, clients can visit them by interfaces. However, it is possible that not all services are visible  to clients, they are just applied internally and don't supply approach to outside, for example: we can assume a InitService service to finish one thing, which just  initialize some system parameter, so it is not necessary to be invoked by outside. It is free to design behave of a service, we advise to follow its responsibility in designing your service. A clearly figures is below; hope you to get our meaning from it.

1.3. Service and Lifecycle

The lifecycle of service may be different, some die at the end of  applications, some die once finishing some thing. But how to control  them?  Designers should be allow to do it in his/hers program

1.4. Service and other Service

Mainly, a service just does some things for outside. It is possible that  a service invokes others during  tasks, this case is allowed. If this, there exists dependency between  some services. 

1.5. Service and Domain

Services are designed to help us do some things for outside and every service just expresses some problems in a domain. In other words, a service maps a domain, and definition of service depends on domain which is a way. In fact, we can regard services as logic AOP. Commonly, a service is not independent, some components are allowed to run on it and work as parts of it. .

1.6. Service and Component

Components can run on services, whose technology is very popular in software programming., programmers design components to finish some business operations. However, if observe these components from higher level: every one is active in a service. When invoke interfaces of a component, a service are implicitly invoked. Concept of service is abstract, and not easy to be caught. In some points, every component should be associated with a service. Of course, it is also feasible that no any components on a service, which can be chose by designers. But services how to hold them? Containers are expected, and components live in them. But what instrument is depended when  instantiating components. Description is a good way for this.

1.7. Component and Description

In most conditions, we use source files to store components and theirs description which may be XML files, properties files or others. This is very commonly in J2EE, if release a pressed file of J2EE components, you will find some class files and some XML files which contain some important information, for example: names of components, transaction and security, and so on. When components are loaded from physical files, description files should be resolved together. Every service should supply a fixed format for its components. Although description of components is a good instrument, if don't find source files contain components, resolving components can’t be continued.

1.8. Source and Detection

We think that a set of mechanism should be applied here to discover source of components, and it is able to detect changes on source of components. For example, if a source file has been deployed, this mechanism should discover it, then raise a notification which contains a changed source. Three types of changes are for source:  new files are found; updated files are detected; deleted files are found; The notification will hold this change information. Source may be xml files or property files or others.

1.9. Source and Identification

If server wants to resolve components from a source, what can it do at first?  Identification, in logic points, a source just contains a kind of components which can map a service. A way should be prepared to identify them. When find one, server will  retrieve a relative service  by source, then components are resolved from the  source. We suggest to put the instrument in service, a interface to do it  is include in our framework.

1.10. Source and Parser

Our goat is deploying components in service containers. Physical files are used to store persistent components,  relative services instantiate components from source by description and do some initialization on them. Because of difference in source description for services, difference is in resolving source. We have designed a parser object to do this task  in our framework.

1.11. Component and Deployment

When components are resolved from source, services do some useful actions on components, for example: deployment. A helper class is designed to do some things for a service, you can add some detailed methods in the helper for services.Before visiting service components, they may have been active in service containers. Due to various services, there exists difference in their deployment. Component  description is very important, when deploy a component on servers, it should be resolved. Sometimes, deployment is a primary path, and so much relative operation hide under deployment. In our points, all operation about components should be around two aspects: Component preparation (deployment) and component invocation, we can regard deployment as begin of components.

      

2.   Framework (Jmservice)

2.1. Objectives

Design a framework to express the above points.

2.2. Classes and Interfaces

Some basal classes and interfaces are defined.

2.2.1.    API Source

         1:  Service.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

/*

 * Why dose our program visit servers? Because servers provide

 * some useful applications to be visited and handle request from

 * clients. This phenomenon is very general in soft world, maybe you

 * enjoy or use these various applications in every day, but you

 * don't care of their concept and internal actions in your brain.

 * Although these applications may be very complex and different,

 * if you are careful, a common character will be found from these

 * applications: all of them just provide some interfaces to be

 * operated by outside, method invocation and contained classes

 * represent these interfaces which are integrated into aspect.

 * In our opinions, we advise to use 'service' word name the

 * concept, every service represents one aspect and used to

 * only handle some problems of one aspect. We can regard the

 * concept of service as logic AOP.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

public interface Service{

}

         2:  Component.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

/*

 * Service component object. Component technology is very popular

 * in software programming. Generally, programmers design theirs

 * components to finish some business operation. In theory, if we

 * observe these components from higher level, every one should do

 * some thing in a aspect. When you invoke component's methods,

 * services are implicitly invoked.<object>Service</object> is

 * an abstract concept, is not easy to be caught. From some points,

 * components should be contained in services, but services how

 * to hold them? Containers are expected for this feature, and

 * components live in containers. However, how are components to

 * moved to service containers? Maybe <object>Assistant</object>

 * can do it.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

public class Component {

  //Description of the Component

  private Desc comDesc;

  //return a description for the component

   public Desc getComDesc() {

    return comDesc;

    }

   //set a description to the component

   public void setComDesc(Desc comDesc) {

     this.comDesc = comDesc;

  }

 }

         3:  Desc.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 /*

 * Component description object. We define this class to describe organization,

 * structure and others for components. In most conditions, physical files are

 * used to store components and theirs description which may be contained in

 * XML files, property files or others, and some important information is in

 * these description files, for example: names of component, transaction, security

 * and so on. Before Instantiating components from <object>Source<object>,

 * description files should be resolved and some properties will be read out,

 * then set these properties to <object>Desc</object> as member value.

 * Every service should provide fixed description format for its components.

 * @author Chris Liao

 * @version 1.0

 * @date 2004/10/01

 * @see Source

 * @see parser

 * @see Discriminator

 */

public interface Desc{}

 

         4:  Source.java

 /*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 /*

 * In most conditions, we use physical files to store components and

 * theirs description. Components will be resolved from <object>Source

 * </object>by its description. A physical file may be a xml file or

 * a property file or a pressed file.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

 public class Source {

}

           5:  Assistant.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 /*

 * A object works as a helper of services, it can be droved to do some things for

 * a service. If you intend to use this framework in your applications, you should

 * implement this interface in your program and add some new methods in its sub

 * classes.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

public interface Assistant{

}

           6:  Parser.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 import java.util.List;

/*

 * Object works as a service parser, which can resolve components from

 * <object>Source</object>.How to resolve? Description of components will be

 * applied for it. The parser should read out description of components from

 * physical files, then instantiate components by its description.

 * This object should work as a member of a service in theory.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

 public interface Parser{

  /**

   * Operation to resolve components from the current source

   *

   * @Parameter List: form of <class>Component</class>

   */

  public List resolve(Source source);

}

         7:  Discriminator.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 /*

 * A object to distinguish the current source is whether belong to a

 * service. Source contains some components and component description.

 * If a service wants to do some things on the current source, it must

 * distinguish the source is whether belong to it, if true, the service

 * will resolve components from it.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

public interface Discriminator {

  /**

   * Identify source is whether belong to some service.

   */

  public boolean identify(Source source);

 }

           8:  Discoverer.java

 /*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 /*

 * A object to discover source for service, this feature is very

 * easy to be acceptable. In J2EE,you may have met some hot-deploy

 * severs, in fact, there are discoverers to do detect source.

 * If source are found, some notification will be occurred.

 * This object may run as a internal thread.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

 public interface Discoverer {

 /**

 * program content to discover service source

 */

  public void run();

 }

         9:  DiscoverEvent.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 import java.util.EventObject;

/*

 * An event object. When source found, event object will be

 * occurred.<member>type</member>indicate event type, we

 * defined three static values for this.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

 public class DiscoverEvent extends EventObject{

   //operation type: new,update,delete.

    private int type = -1;

   //Event constructor

    public DiscoverEvent(Source source,int type) {

      super(source);

      this.type = type;

    }

    //return event operation type on source

    public int getType(){

      return this.type;

    }

  //return target source

    public Source getEventSource(){

    return (Source)super.getSource();

     }

     //indicate that an new source is found

    public final static int NEW = 0;

     //indicate that a updated source is found

    public final static int UPDATE = 1;

     //indicate that a delete source is found

    public final static int DELETE = 2;

}

         10:  DiscoverListener.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.service;

 import java.util.EventListener;

/*

 * An event listener object to handle events. When events raised,

 * listeners will catch them, and do some logic operations for

 * came events, for example: deploying, undeploying, redeploying.

 * Of course, you also add other logic for you application.

 * @author Chris liao

 * @version 1.0

 * @date 2004/10/01

 */

public interface DiscoverListener extends EventListener{

    //method to handle a new source.

    public void newSource(DiscoverEvent event);

    //method to handle a updated source.

    public void updateSource(DiscoverEvent event);

    //method to handle a deleted source.

  public void deleteSource(DiscoverEvent event);

}

2.2.2.    Static Relationship

3.   Jmservice in J2EE server

3.1. Objectives

1: Build a server architecture (Jmserver) on this framework.

2: Simplifies server structure and make logic clearer

3: Tell you how to organize services and deploy components

4: Show advantage and features of this framework.

3.2. What in J2EE Server?

There are some applications contained in J2EE servers, for example: Naming, JDBC, Transaction, EJB, and so on. If you are a J2EE programmer, you may meet the following things:

1: Binding and resolving objects in Naming

2: Configuring data source in JDBC domain

3: Deploying EJB components in EJB containers

If be careful, a common feature is found from them: every one provides some operations for outside in explicit way or in implicit way. This matches the features in our framework. We can regard these applications as services applied in J2EE

3.3. Characters of service

What can these J2EE services do? They let some j2ee components run on them. Commonly, before visiting components, they should have been deployed. In our points, deployment (Component preparation) and component invocation are two main lines and many logic operations hide under them. If a component is expected to be deployed in a server, it should be acceptable by the server and the description of  the component is a key. Some features from j2ee services are listed below.

1: Service invocation

2: Component description

3: Component deployment

3.4. Configuration of Service

An XML file to integrate all services in a J2EE server and advise to drive IOC mechanism to resolve this file. The file format is below:

3.4.1.1.     File format

 <services>

 <service>

  <name>service_xxx1</name>

  <service_class>org.jmin.xxxx1</service_class>

  </service>

  <service>

   <name>service_xxx2</name>

   <service_class>org.jmin.xxxx2</service_class>

  </service>

</services>

3.4.1.2.     Order in the file

Services defined in this file must follow an expected order, which is a load order. When a service is being instantiated, it may invoke others. Dependency exists between services. The depended service should be loaded earlier. Developers should think over the order for their application, then organize them in the file.

3.4.1.3.     Service List in Jmin

Service Name

Description

ORBService*

Startup server orb

Nameservice*

Java name service

JDBCService

Provide j2ee data source

TrnasactionService

Provide j2ee transition

EJBService

Run EJB components

WebService

Run web components

 

 

DiscoverService*

Discover j2ee source (it must be at the end of the order)

3.5. Management of service

A locate can be found to manage services, for example: load services, registering services and unregistering services. We have defined an object to do them in the server architecture, please note the source

3.6. How to launch service?

Once run server, services will be loaded into memory, then do some initialization for them. There exists a load order for services; please refer to the content in configuration subject.

3.7. How to discover j2ee source?

When J2EE programmers deploy their components in servers, a set of mechanism is necessary to discover them. The Jmserver  architecture provides a  sub framework to discover component source, we named it as Jmdiscover framework, which run as a J2EE service in Jmserver architecture. More detail, please read the source of it.

3.8. How to deploy components?

Deployment is primary in J2EE servers. Different types of components hold different description and map different deployment. A J2EE Assistant are designed to do the deployment task and contained in Jmserver architecture.

3.9. Relationship between Jmservice,Jmserver,Jmdiscover

3.10. Classes and Interfaces

3.10.1.    API Source

3.10.1.1.     Source in Jmserver

1: J2EEService .java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Service;

/*

 * A super interface for all sub services in jmin server, which are core

 * in our server. About description of services, a XML file is defined for

 * this, and IOC mechanism will resolve the xml file. 

 *@author Chris liao

 *@version 1.0

 */

public interface J2EEService extends Service{

  /**

   * Parser for current service, service object can use it

   * to resolve components; value is allowed to be null

   */

   public J2EESourceParser getParser();

   /**

   * Assistant to help current service to do some operation.

   * value is allowed to be null

   */

  public J2EEAssistant getAssistant();

   /**

   * Discriminator to distinguish components is whether belong to the current

   * service. value is allowed to be null

   */

   public J2EESourceDiscriminator getDiscriminator();

  /**

   * do some initialization for the current service

   */

  public void init();

  /**

   * launch the current service and make it ready to be requested

   */

  public void start();

  /**

   * stop serive

   */

  public void stop();

}

2: J2EEAssistant.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Assistant;

/*

 * <class>J2EEAssistant</class> is an extended sub interface for services.

 * Its sub implemented instance are used do some some operation on j2ee

 * componnents, for example: deploy, undeploy and redploy. Commonly, today's

 * most of development are based on component technology, and they are

 * active in server containers. How are they moved to server containers

 * from Repositorties? This class help us to do it.

 * @author Chris liao

 * @version 1.0

 */

public interface J2EEAssistant extends Assistant{

  //deploy a component

  public void deploy(J2EEComponent com)throws J2EEComponentException;

  //undeploy a component

  public void undeploy(J2EEComponent com)throws J2EEComponentException;

  //redeploy a component

  public void redeploy(J2EEComponent com)throws J2EEComponentException;

}

3: J2EEComponent.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Component;

/*

 * <class>J2EEComponent</class> is a sub interface extended

 * from service framework.

 * @author Chris Liao

 * @version 1.0

 */

public class J2EEComponent extends Component{

}

4: J2EEComponentDesc.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Desc;

/*

 * Description fpr j2ee components,which are contained in

 * <object>J2EESource</object>

 * @author Chris Liao

 * @version 1.0

 */

public interface J2EEComponentDesc extends Desc {

}

5: J2EEDiscoverer.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Discoverer;

/*

 * A j2ee source discoverer to discover j2ee source,

 * when new source found or changes on source, a notification

 * will be occurred.

 */

public interface J2EEDiscoverer extends Discoverer{

}

6: J2EEServiceDesc.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Desc;

/*

 * A description object for j2ee service, which is used in service initialization

 * @author Chris Liao

 * @version 1.0

 */

public class J2EEServiceDesc implements Desc{

}

7: J2EEServiceDescLoader.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import java.io.InputStream;

import java.io.FileInputStream;

import java.util.List;

import java.util.ArrayList;

import javax.xml.parsers.*;

import org.w3c.dom.*;

/*

 * A service loader to load services from physical files,

 * some description about service are defined in a file:

 * service.xml

 * @author Chris Liao

 * @version 1.0

 */

public class J2EEServiceDescLoader {

  //@TOTO We can replace it with a better way to resolve services

  //we assume that IOC is expected.   

  public static List parse(String serviceFile){

  }

}

8: J2EEServiceFactory.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

/*

 * A factory for j2ee services and create a new service instance

 * by its description

 * @author Chris Liao

 * @version 1.0

 */

public class J2EEServiceFactory {

 //method to create a new J2EE service

  public static J2EEService create(J2EEServiceDesc desc)

      throws InstantiationException{

  }

}

9: J2EESource.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import java.io.File;

import org.jmin.service.Source;

/*

 * A Source object for j2ee components.

 * Source may be a xml file or a property file or a jar file.

 * @author Chris Liao

 * @version 1.0

 */

public class J2EESource extends Source{

    //source file

    private File source;

    //constructor with a source file

    public J2EESource(File j2eeFile){

      this.source = j2eeFile;

    }

     //return s source file

    public File getSourceFile(){

    return this.source;

  }

}

10: J2EESourceDiscriminator.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Discriminator;

/*

 * A J2EE Source Discriminator, which helps to distinguish Source

 * is whether belong to a j2ee service.

 * @author Chris Liao

 * @version 1.0

 */

public interface J2EESourceDiscriminator extends Discriminator{

}

11 J2EESourceParser.java

 /*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.Parser;

/*

 * A J2EE Source Parser.J2EE service use its instance to resolve j2ee

 * components from <class>J2EESource</class>

 * @author Chris Liao

 * @version 1.0

 */

public interface J2EESourceParser extends Parser{

}

12: ServiceManager.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import java.util.List;

import java.util.Map;

import java.util.HashMap;

/*

 * J2EE service Manager,which can <method>register</method> and

 * <method>unregister</method> to operate j2ee service.

 * @author Chris Liao

 * @version 1.0

 */

public class ServiceManager {

    public synchronized void register(String name, J2EEService service)throws ServiceAlreadyExist{

    }

    /unregister a j2ee service with a name

   public synchronized void unregister(String name, J2EEService service)throws ServiceNotFoundException{

    }

    //load services from config file: service.xml

   private synchronized void loadService()

   }

  /**

  *return a list contained all services

 */

    public synchronized Map getAllService(){

    }

     /**

     * Return file path for service.xml

     * Before retrieving this property:serviceFile from <object>System<object>,

     * it must be setted during the initialization of your application

     */

     private String getServiceDescFile(){

        return System.getProperty("serviceFile");

     }

 }

13: J2EEDiscoverEvent.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.DiscoverEvent;

/*

 * When a new j2ee source or changes on source,

 * this object will be created as a notification.

 * @author Chris Liao

 * @version 1.0

 */

public class J2EEDiscoverEvent extends DiscoverEvent{

    //Event constructor

    public J2EEDiscoverEvent(J2EESource source,int type) {

    super(source,type);

  }

}

14: J2EEDiscoverListener.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.j2eeService;

import org.jmin.service.DiscoverListener;

/*

 * This object can catch source events,then do some thing

 * by them,for example:deploying components,undeploying components,

 * redeploying components.

 * @author Chris Liao

 * @version 1.0

 */

public interface J2EEDiscoverListener extends DiscoverListener{

}

3.10.1.2.     Source in Jmdiscover

1: JminDiscoverService.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.discover;

import java.util.Timer;

import org.jmin.j2eeService.J2EEService;

import org.jmin.j2eeService.J2EEAssistant;

import org.jmin.j2eeService.J2EESourceParser;

import org.jmin.j2eeService.J2EESourceDiscriminator;

/*

 * <class>JminDiscoverService<class>is important service in our

 * server, which is a monitor and discover j2ee source.

 * The service mast be at the end of service.xml

 * @author Chris Liao

 * @version 1.0

 */

public class JminDiscoverService implements J2EEService {

    //A timer for discover service

    private Timer timer;

  //A discoverer

    private JminDiscoverer discoverer;

  //init

    public void init(){

    this.timer = new Timer(true);

    this.discoverer = new JminDiscoverer(getDeployFolder());

    JminDeployListener listener = new JminDeployListener();

    this.discoverer.addDiscovererListener(listener);

    }

     //start the serivce

    public void start(){

       this.timer.schedule(discoverer,500);

        System.out.println("Discover service has been started!");

   }

    //stop the service

    public void stop(){

      System.out.println("Discover service has been stop!");

   }

    //null valuve

   public J2EESourceParser getParser(){

     return null;

  }

  //null valuve

  public J2EEAssistant getAssistant(){

    return null;

  }

  //null valuve

  public J2EESourceDiscriminator getDiscriminator(){

    return null;

  }

  /**

   * Retrieve deploy folder

   * Before retrieving this property: DeployFolder from <object>System<object>,

   * it must be stetted during the initialization of your application

   */

  private String getDeployFolder(){

      return System.getProperty("DeployFolder");

  }

}

2: JminDeployListener.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.discover;

import java.util.List;

import java.util.Iterator;

import java.util.Collection;

import org.jmin.service.DiscoverEvent;

import org.jmin.j2eeService.J2EEService;

import org.jmin.j2eeService.J2EEAssistant;

import org.jmin.j2eeService.J2EEComponent;

import org.jmin.j2eeService.J2EEDiscoverEvent;

import org.jmin.j2eeService.J2EEDiscoverListener;

import org.jmin.j2eeService.J2EEComponentException;

import org.jmin.j2eeService.ServiceManager;

/*

 * Object to catch source evnet

 * @author Chris Liao

 * @version 1.0

 */

public class JminDeployListener implements J2EEDiscoverListener{

 /**

  * occurs when a new source found

  */

public void newSource(DiscoverEvent event){

    internal(event);

  }

  /**

   * occurs when a updated source found

   */

  public void updateSource(DiscoverEvent event){

    internal(event);

  }

  /**

   * occurs when a deleted source found

   */

  public void deleteSource(DiscoverEvent event){

    internal(event);

  }

   //internal operation

  private void internal(DiscoverEvent event){

    J2EEDiscoverEvent j2Event = (J2EEDiscoverEvent)event;

    Collection con = ServiceManager.getInstance().getAllService().values();

    Iterator itor = con.iterator();

    while(itor.hasNext()){

      J2EEService service = (J2EEService)itor.next();

     

      //if any member value is null, continue with the next service.

      if(service.getAssistant() == null ||

         service.getParser() == null ||

         service.getDiscriminator() == null)

        continue;

      if(service.getDiscriminator().identify(event.getEventSource())){

        List list = service.getParser().resolve(event.getEventSource());

        for(int i=0; i<list.size();i++){

          J2EEComponent comp = (J2EEComponent)list.get(i);

          try{

            switch(event.getType()){

              case J2EEDiscoverEvent.NEW:

                {((J2EEAssistant)service.getAssistant()).deploy(comp); break;}

              case J2EEDiscoverEvent.DELETE:

                {((J2EEAssistant)service.getAssistant()).undeploy(comp); break;}

              case J2EEDiscoverEvent.UPDATE:

                {((J2EEAssistant)service.getAssistant()).redeploy(comp); break;}

              default:break;//break switch scope

            }

          }catch(J2EEComponentException e){

              e.printStackTrace();

          }

        }

        break;//break repetition

      }

    }

  }

 }

 

3: JminDiscoverer.java

/*

*Copyright 2006 jmin. All rights reserved.

*/

package org.jmin.discover;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.util.List;

import java.util.ArrayList;

import java.util.TimerTask;

import org.jmin.j2eeService.J2EESource;

import org.jmin.j2eeService.J2EEDiscoverer;

import org.jmin.j2eeService.J2EEDiscoverEvent;

import org.jmin.j2eeService.J2EEDiscoverListener;

/*

 * Detect some folders to find j2ee components, when files in folder has been

 * changed, a event associated with the files will be occurred at once. The change

 * may be deploying, undeploying and redeploying.

 * @author Chris liao

 * @version 1.0

 */

public class JminDiscoverer extends TimerTask implements J2EEDiscoverer{

     //init discoverer

   private void init(String deployFolder){

    this.deployFolder = new File(deployFolder);

    this.tmpFolder = new File(getTempFolder());

    if(!tmpFolder.exists())

      tmpFolder.mkdir();

  }

  /**

   * Main method to detect deploy folder

   */

  public void run(){

    this.retrieveCurrentFileList();

    this.detectNewComponents();

    this.detectDeletedComponents();

    this.detectUpdaedComponents();

     //hot deploy: copying files should be move to services

    for(int i=0; i< newFiles.size();i++){

      FilePair filePair =(FilePair)newFiles.get(i);

      File file = filePair.getFile();

      J2EEDiscoverEvent event = new J2EEDiscoverEvent(new J2EESource(file),J2EEDiscoverEvent.NEW);

      this.publishEvent(event);

    }

    for(int i=0; i< deletedFiles.size();i++){

      FilePair filePair =(FilePair)deletedFiles.get(i);

      File file = filePair.getFile();

      J2EEDiscoverEvent event = new J2EEDiscoverEvent(new J2EESource(file),J2EEDiscoverEvent.DELETE);

      this.publishEvent(event);

    }

    for(int i=0; i< updatedFiles.size();i++){

      FilePair filePair =(FilePair)updatedFiles.get(i);

      File file = filePair.getFile();

      J2EEDiscoverEvent event = new J2EEDiscoverEvent(new J2EESource(file),J2EEDiscoverEvent.UPDATE);

      this.publishEvent(event);

    }

    lastFileList.clear();

    lastFileList.addAll(curFileList);

  }

  /**

   * publish a source event. All listeners will listen it.

   */

  private void publishEvent(J2EEDiscoverEvent event){

    if(listeners != null){

      for(int i =0;i<listeners.size();i++){

        J2EEDiscoverListener listener = (J2EEDiscoverListener)listeners.get(i);

        switch(event.getType()){

          case J2EEDiscoverEvent.NEW: {listener.newSource(event);break;}

          case J2EEDiscoverEvent.DELETE:{listener.deleteSource(event);break;}

          case J2EEDiscoverEvent.UPDATE:{listener.updateSource(event);break;}

          default:break;

        }

      }

    }

  }

  /**

   * return a file list with new files in deploy folder

   */

  private List detectNewComponents(){

   }

  /**

   * return a file list with deleted files

   */ 

  private List detectDeletedComponents(){

  }

  /**

   * return a file list with updated files in the deploy folder

   */

   private List detectUpdaedComponents(){

   }

  //register a new listener

   public void addDiscovererListener(J2EEDiscoverListener listener){

   }

  //unregister a listener

  public void removeDiscovererListener(J2EEDiscoverListener listener){

  }

}

3.10.2.    Static relationship in Jmserver

3.10.3.    Control flow in Jmserver

4.   Jmservice in others

We just build j2ee architecture to show the service framework, which is a application sample. You can also extend it in other domains for you system. We think service should hold more way, for example: service handles request form client, during 2004, I designed one for this way, you can visit the website: http://obframework.home4u.china.com

 

5.   About the author

Chris Liao, a system analyst, who lives in china, and has over six years of experience in java, he is fond of J2ee technology. You can contact him with the following way:

Mail: Obframework@21cn.com

Mobile: 13532790758(Shenzhen china)

 

Get the framework source and the architecture source applied in j2ee server:

Copyright © 2006 . All Rights Reserved.