Giter Club home page Giter Club logo

mobileoffice's Introduction

MobileOffice

ExoBrain 프로젝트

모델 라이브러리 소스 코드 예제

public class MobileOfficeSimulator {

	public static void main(String[] args) {
		

		/* create mobile office block 4 by 4 */
		MobileOffice.createOfficeBlock(4, 4);
		
		/* instantiate with environment */
		OfficeBlock block = new OfficeBlockBuilder()
				.xPos(0).yPos(0)
				.brightness(60)
				.humidity(55)
				.temperature(25)
				.createOfficeBlock();
	
		MobileOffice.assignBlock(block);
		
		MobileOffice.printCurrentState();
	
		/* instantiate device & assign to mobile office */
		AirCon aircon = new AirCon(0 , 0);
		MobileOffice.addDevice(aircon);
		
		/* operate device in duration time */
		aircon.cool(3);
	
		MobileOffice.printCurrentState();
		
		System.out.println(MobileOffice.getSerializedJson());
	}
}

통신 기법 : OSGi HTTP Rest

1-1. 새 개발환경 설정

Eclipse 역시 OSGi플랫폼 위에 구동되므로 새로운 타겟 플랫폼을 생성하여 기존의 IDE에 변경이 없는 개발 환경을 만들어야 합니다.


Eclipse 의 상단 메뉴 중 Preference - Plugin Development 에서 Target Platform에서 새로운 타겟 플랫폼을 추가합니다.


여타 다른 번들들은 필요하지 않으므로 Nothing 으로 플랫폼을 생성합니다.


개발시 필요한 OSGi - HTTP REST 를 지원하는 라이브러리를 추가합니다.

http://download.eclipse.org/eclipse/updates/4.3
를 추가하여 "Equinox Target Components" 를 설치합니다.

http://hstaudacher.github.io/osgi-jax-rs-connector
를 추가하여 "OSGi - JAX -RS Connector" 를 설치합니다. 그외 번들들은 기타 서비스를 이용할 때 필요합니다.

1-2. 어플리케이션 생성


새 프로젝트를 생성할 때 Target 을 Equinox로 설정해줍니다.


프로젝트 생성 후 MANIFEST.MF 를 다음과 같이 JAX-RS API를 이용할 수 있게 설정해줍니다.

1-3. 소스 코드 작성

ExampleResource.java

/* annotation 을 통해 경로 지정 */
@Path( "/hello" )
public class ExampleResource {
	@GET
	public String helloWorld() {
		return "Hello World";
	}
}

Activator.java

public class Activator implements BundleActivator {
	private ServiceRegistration<ExampleResource> registration;

	public void start(BundleContext bundleContext) throws Exception {
		/* 서비스 등록 */
		registration = bundleContext.registerService(ExampleResource.class, new ExampleResource(), null);
	}

	public void stop(BundleContext bundleContext) throws Exception {
		registration.unregister();
	}
}

1-4. 실행


실행을 위해선 다음과 같은 번들들이 필요합니다.

// Our Application osgi.rest.example

// The OSGI implementation org.eclipse.osgi org.eclipse.osgi.services

// The OSGi console org.eclipse.equinox.console org.apache.felix.gogo.command org.apache.felix.gogo.runtime org.apache.felix.gogo.shell

// The OSGi HttpService implementation org.eclipse.equinox.http.jetty org.eclipse.equinox.http.servlet org.eclipse.jetty.continuation org.eclipse.jetty.http org.eclipse.jetty.io org.eclipse.jetty.security org.eclipse.jetty.server org.eclipse.jetty.servlet org.eclipse.jetty.util javax.servlet-api

// The JAX-RS Connector com.eclipsesource.jaxrs.publisher

// Jersey com.eclipsesource.jaxrs.jersey-all (this is Jersey repackaged as a single bundle)


HTTP 서비스를 이용하기 위해 Run 혹은 Debug 설정에서 OSGi 실행 Argument에 -Dorg.osgi.service.http.port=포트 번호 를 추가해줍니다.


다음과 같은 실행결과가 나옵니다.

Ref : http://eclipsesource.com/blogs/2014/02/04/step-by-step-how-to-bring-jax-rs-and-osgi-together/

mobileoffice's People

Watchers

kyeongwook.ma avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.