'gogo 콘솔 확장'에 해당되는 글 1건

  1. 2010.12.06 Apache Felix Gogo 콘솔 확장하기
Programming/OSGi2010. 12. 6. 11:20

Apache Felix Gogo 콘솔 확장하기

1. Felix Gogo

             Felix Gogo Apache에서 나온 OSGi framework를 위한 진보한 shell이다

2. 인터페이스

             Felix Gogo Console을 사용하기 위해 다음의 인터페이스를 구현하여 OSGi 서비스로 등록해야 한다. (서비스 등록방법은 지난 포스팅 참조) 하지만 인터페이스를 구현 한다고 해서 이 모든 메서드를 구현해 줄 필요는 없다. 자신이 원하는 메서드는 따로 만들어서 서비스 등록할 때 프로퍼티 파일에 참조해 주기만 하면 되기 때문이다.

public interface org.apache.felix.service.command.CommandSession {

Object execute(CharSequence commandline) throws Exception;

Object get(String name);

void put(String name, Object value);

    ...

}


Felix Gogo를 사요하기 위해 Maven에서 다음의 dependency를 추가해 줘야 한다.


            <dependency>

                      <groupId>org.apache.felix</groupId>

                      <artifactId>org.apache.felix.gogo.command</artifactId>

                      <version>0.6.0</version>

           </dependency>


 

3. 서비스 등록

             3-1. Console에서 실행할 메서드 구현

                          public class TestConsole implements CommandSession {

                                       public void test1(String x) {

                                                     System.out.println(x);

                                       }

                                       public void test2(String y) {

                                                     System.out.println(y);

                                       }

 

                                       //CommandSession를 구현하는 메서드

                                       @Override

                                       public Object execute(CharSequence arg0) throws Exception {

                                                    // TODO Auto-generated method stub

                                                     return null;

                                       }

                                       ….

                          }

             3-2. 서비스 등록

                          Dictionary<String, Object> dict = new Hashtable<String, Object>();

                           dict.put(CommandProcessor.COMMAND_SCOPE, "shell");

                           dict.put(CommandProcessor.COMMAND_FUNCTION, new String[] {"test1", "test2"});

                          context.registerService(org.apache.felix.service.command.CommandSession.class.getName(),

                             new TestConsole(context), dict);

 

위와 같이 인터페이스를 구현해서 서비스에 등록하면 프로퍼티로 넘겨준 dict에 담겨있는 메서드 test1, test2Console에서 실행할 수 있다. OSGi Console에서 help를 치면 shell:test1shell:test2가 등록되어 있는 것을 확인 할 수 있으며 test1 “Hello world” 라고 치면 Hello world OSGi Console에 찍히는 것을 확인 할 수있을 것이다.

객체 파라미터, 리턴 값에 대해서는 믿에 링크를 확인해 보길 바란다.
 

참고:

http://felix.apache.org/site/rfc-147-overview.html#RFC147Overview-StandardwaytoimplementandruncommandsforanyOSGi4.2framework

Posted by Brian B. Lee