Results 1 to 3 of 3

Thread: control bus integration

  1. #1
    Join Date
    Aug 2006
    Posts
    129

    Default control bus integration

    i really like this addition ;
    i defined a control bus along with a gateway to link it with the command :

    Code:
    <context:annotation-config/>
    
    	<int:channel id="request-command"/>
    	<int:channel id="respons-command"/>
    
    	<int:gateway default-request-channel="request-command" default-reply-channel="respons-command" service-interface="wims.tijd.shell.ControlBusGateway" />
    
    	<int:control-bus input-channel="request-command" output-channel="respons-command"/>
    	
    	<bean class="wims.tijd.shell.ControlBusCommand"/>
    Code:
    public interface ControlBusGateway {
    	
    	@Gateway
    	Object send(String command);
    
    }
    Code:
    @Component
    public class ControlBusCommand implements CommandMarker, ApplicationContextAware {
    	
    	@Inject ControlBusGateway cbg;
    	
    	ApplicationContext applicationContext;
    	
    	@CliCommand(value = "controlbus", help = "Print a simple hello world message")
    	public String send(
    			@CliOption(key = { "identifier" }, mandatory = true, help = "Beanname") final String identifier,
    			@CliOption(key = { "operation" }, mandatory = true, help = "Method") final String operation){
    		
    		Object returned = cbg.send("@'"+identifier+"'."+operation);
    		if(returned == null){
    			return "command exucted.";
    		}else{
    			return returned.toString();
    		}
    	}
    	
    	@CliCommand(value = "listBeans", help = "Print a simple hello world message")
    	public String listBeans(){
    		
    		StringBuilder sb = new StringBuilder(this.applicationContext.getDisplayName()).append("\n");
    		
    		
    		for(String name : this.applicationContext.getBeanDefinitionNames()){
    			sb.append(name).append("=").append(this.applicationContext.getBean(name).getClass()).append("\n");
    		}
    		
    		return sb.toString();
    		
    	}
    
    	@Override
    	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    		this.applicationContext = applicationContext;
    	}
    
    }
    Code:
    spring-shell>controlbus --identifier errorChannel --operation componentType
    publish-subscribe-channel
    spring-shell>

  2. #2
    Join Date
    Aug 2004
    Location
    New York, NY
    Posts
    74

    Default

    Hi,

    Nice to hear you are finding it useful. One improvement I can suggest for this command is to pass in the SpEL expression vs. separating it out into the bean name and the operations that assumes no-arg. Quite a few SI operations like channel adapter start, stop, status take zero arguments, but in more complex cases there will be method arguments. Also, the control bus can also take groovy or other JVM based scripts... what about

    >controlbus --spel -expression @bean.operation("foo","bar",1)
    >controlbus --script cool-script.groovy


    Cheers,
    Mark

  3. #3

    Default

    Nice post.. Thanks for sharing such a best information. It is more useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •