반응형

 

 

 

 

 

 

 

 

 

 

 

 

1. Using 'full' and 'empty' variables

to make producer wait when buffer is full, and to make consumer wait when buffer is empty

 

 

 

 

 

 

 

2. Fix deadlocked code

: It should be same order between producer's sem_init and consumer's sem_init

Because if the sem_init order is not the same, it will be in the following state

mutex1 = 0, mutex2 = 0

So, nobody can pass sem_init.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형
반응형

 

 

 

 

 

 

 

 

 

 

1. 쓰레드 기법을 사용하여 공유 변수를 사용해 통신하는 생산자 / 소비자 프로그램

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2. 세마포를 사용하여 공유 변수에 대해서 상호배제를 구현한 프로그램

: flag 변수를 통해 producer 의 printf가 consumer의 printf보다 항상 먼저 나오도록 구현한다.

 

 

 

 

- > mutex = 1, flag = 0으로 초기화한다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형
반응형

 

 

 

 

 

 

 

We will gonna execute project in Eclipse.

1. new > maven project > maven-archetype-webapp > enter an artifact id > finish

 

2. changing java version in pom.xml

1.7 -> 1.8

 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

 

 

 

3. add servlet dependency at pom.xml

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    
     <dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.45</version>
	</dependency>

And don't forget to click [ maven > Update Project ] to adapt the settings.

Restart Eclipse.

 

 

 

4. Editing Web.xml

 

Open Navigator

src > main > webapp > WEB-INF > web.xml

 

change from

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
</web-app>

to

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>Archetype Created Web Application</display-name>
</web-app>

 

 

 

 

5. Change web module version

 

open navigator

.settings/org.eclipse.wst.common.project.facet.core.xml

 

You can see like this in xml file

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="2.3"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.8"/>
</faceted-project>

 

change version from "2.3" to "3.1"

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="3.1"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.8"/>
</faceted-project>

 

 

 

 

 

 

 

 

 

6. Make src/main/java 

 

src > main > [ make java file ]

And there will be src/main/java

 

and make package which names like 'kr.or.connect.blahblah'

 

 

 

 

So, our Maven Setting is all end

 

 

반응형
반응형

 

 

 

 

 

 

 

1. Spring Framework란?

 

  • 엔터프라이즈급 어플리케이션을 구축할 수 있는 가벼운 솔루션이자, 원스-스탑-숍(One-Stop-Shop)
  • 원하는 부분만 가져다 사용할 수 있도록 모듈화가 잘 되어 있습니다.
  • IoC 컨테이너입니다.
  • 선언적으로 트랜잭션을 관리할 수 있습니다.
  • 완전한 기능을 갖춘 MVC Framework를 제공합니다.
  • AOP 지원합니다.
  • 스프링은 도메인 논리 코드와 쉽게 분리될 수 있는 구조로 되어 있습니다.

 

 

 

 

 

 

 

2. 프레임 워크 모듈

  • 스프링 프레임워크는 약 20개의 모듈로 구성되어 있습니다.
  • 필요한 모듈만 가져다 사용할 수 있습니다.

 

 

 

3. AOP 와 인스트루멘테이션 (Instrumentation)

  • spring-AOP : AOP 얼라이언스(Alliance)와 호환되는 방법으로 AOP를 지원합니다.
  • spring-aspects : AspectJ와의 통합을 제공합니다.
  • spring-instrument : 인스트루멘테이션을 지원하는 클래스와 특정 WAS에서 사용하는 클래스로 더 구현체를 제공합니다. 참고로 BCI(Byte Code Instrumentations)은 런타임이나 로드(Load) 때 클래스의 바이트 코드에 변경을 가하는 방법을 말합니다.

 

 

 

 

 

4. 메시징(Messaging)

  • spring-messaging : 스프링 프레임워크 4는 메시지 기반 어플리케이션을 작성할 수 있는 Message, MessageChannel, MessageHandler 등을 제공합니다. 또한, 해당 모듈에는 메소드에 메시지를 맵핑하기 위한 어노테이션도 포함되어 있으며, Spring MVC 어노테이션과 유사합니다.

 

 

 

5. 데이터 엑서스(Data Access) / 통합(Integration)

  • 데이터 엑세스/통합 계층은 JDBC, ORM, OXM, JMS 및 트랜잭션 모듈로 구성되어 있다.
  • spring-jdbc : 자바 JDBC프로그래밍을 쉽게 할 수 있도록 기능을 제공합니다.
  • spring-tx : 선언적 트랜잭션 관리를 할 수 있는 기능을 제공합니다.
  • spring-orm : JPA, JDO및 Hibernate를 포함한 ORM API를 위한 통합 레이어를 제공합니다.
  • spring-oxm : JAXB, Castor, XMLBeans, JiBX 및 XStream과 같은 Object/XML 맵핑을 지원합니다.
  • spring-jms : 메시지 생성(producing) 및 사용(consuming)을 위한 기능을 제공, Spring Framework 4.1부터 spring-messaging모듈과의 통합을 제공합니다.

 

 

6. 웹(Web)

  • 웹 계층은 spring-web, spring-webmvc, spring-websocket, spring-webmvc-portlet 모듈로 구성됩니다.
  • spring-web : 멀티 파트 파일 업로드, 서블릿 리스너 등 웹 지향 통합 기능을 제공한다. HTTP클라이언트와 Spring의 원격 지원을 위한 웹 관련 부분을 제공합니다.
  • spring-webmvc : Web-Servlet 모듈이라고도 불리며, Spring MVC 및 REST 웹 서비스 구현을 포함합니다.
  • spring-websocket : 웹 소켓을 지원합니다.
  • spring-webmvc-portlet : 포틀릿 환경에서 사용할 MVC 구현을 제공합니다.

 

 

Q. 프레임워크와 라이브러리의 차이는 무엇일까?

A. 프레임워크는 골격이 아닐까 싶습니다. 프레임워크라는 골격을 기반으로 우리가 원하는대로 살을 붙여 제품을 만드는 것입니다. 그리고 그 살을 붙일 때 효과적으로 붙일 수 있도록 도와주는 도구가 라이브러리라고 생각합니다.

 

 

 

 

1. Spring Framework란?

- A lightweight solution for deploying enterprise-class applications, one-stop-shop
- It is well modularized so that you can use only the parts you want.
- This is an IoC container.
- You can manage transactions declaratively.
- Provides a fully functional MVC framework.
- AOP is supported.
- The spring has a structure that can be easily separated from the domain logic code.

 

 

 

2. Framework Module

The spring framework consists of approximately 20 modules.
Only the modules you need can be imported and used.


3. AOP Instrumentation

spring-AOP : supports AOP in a way that is compatible with the AOP Alliance.
spring-spect : provides integration with AspectJ.
spring-instrument : Provides more implementation into classes that support instrumentation and classes used by certain WASs. Note that Byte Code Instrumentation (BCI) refers to how to change the class' byte code at runtime or load.

 

 

 

 

4. Messaging

Spring-messaging: Spring Framework 4 provides messages, message channels, message handlers, and more to create message-based applications. The module also contains an annotation for mapping messages to the method, similar to Spring MVC annotation.



5. Data Access / Integration

The data access/integration layer consists of JDBC, ORM, OXM, JMS, and transaction modules.
spring-jdbc : Provides functionality to facilitate Java JDBC programming.
spring-tx : Provides the ability to manage declarative transactions.
spring-orm : Provides an integrated layer for ORM API including JPA, JDO, and Hibernate.
spring-oxm : JAXB, Castor, XMLBeans, JiBX 및 XStream과 같은 Object/XML 맵핑을 지원합니다.
Spring-jms: Provides functionality for generating and using messages and provides integration with spring-messaging modules from Spring Framework 4.1.

 

 

 

 

 

6. Web (Web)
- Web layer is consist of spring-web, spring-webmvc, spring-websocket, spring-webmvc-portlet modules.
- Spring-web: It provides web-oriented integration functions such as multi-part file upload and servlet listener. Provides Web-- - related parts for remote support for HTTP clients and Spring.
- spring-webmvc : also known as Web-Servlet Module, includes Spring MVC and REST Web Service implementations.
- spring-websocket : supports web sockets.
- spring-webmvc-portlet : Provides MVC implementation for use in portlet environment.

 

 

 

Q. What is the diffrence between framework and library ?

A. I think the framework is a skeleton. Based on the framework, we make the products as we want. And libraries are the tools that we use at that time.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형
반응형

 

 

 

 

 

 

1. 데이터베이스에 접속하기

mysql -h127.0.0.1 -uconnectuser -p connectdb

 

2. 비밀번호 입력

쏼라쏼라

 

 

 

 

 

 

 

 

 

반응형
반응형

 

 

 

 

 

 

 

1. Web API 디자인 가이드

  • URI는 정보의 자원을 표현해야 합니다.
  • 자원에 대한 행위는 HTTP Method(GET, POST, PUT, DELETE)로 표현합니다.

 

 

자원에 대한 행위는 HTTP Method로 표현

 

 

 

 

2. URI는 정보의 자원을 표현해야 한다.

  • GET /members
    : 위의 표현은 맴버의 모든 정보를 달라는 요청입니다.
  • GET /members/delete/1
    : GET은 정보를 요청할 때 사용합니다. 위와 같이 동사로 삭제를 표현하면 안 됩니다.
  • DELETE /members/1
    : HTTP Method 중의 하나인 DELETE를 이용하여 삭제를 표현해야 합니다.

 

3. 자원에 대한 행위는 HTTP Method로 표현

  • GET /members/1                   (o)
  • GET /members/get/1             (x)
  • GET /members/add                 (x)
  • POST /members                       (o)
  • GET /members/update/1        (x)
  • PUT /members/1                     (o)
  • GET /members/del/1               (x)
  • DELETE /members/1               (o)

 

 

 

 

4. 슬래시 구분자(/)는 계층을 나타낼 때 사용

http://domain/houses/apartments

http://domain/departments/1/employees

  • URI 마지막 문자로 슬래시 구분자(/)를 포함하지 않습니다.
  • 하이픈(-)은 URI가독성을 높일 때 사용합니다.
  • 언더바(_)는 사용하지 않습니다.
  • URI경로는 소문자만 사용합니다.
  • RFC 3986(URI 문법 형식)은 URI스키마와 호스트를 제외하고는 대소문자를 구별합니다.
  • 파일 확장자는 URI에 포함하지 않습니다.
  • Accept Header를 사용합니다.

 

 

 

 

5. 상태 코드

상태 코드 (성공)

 

 

 

 

 

상태 코드 (클라이언트로 인한 오류)

 

 

 

 

 

 

 

상태 코드 (서버로 인한 오류)

 

 

 

 

 

6. Web API 실습 코드

 

<!-- web.xml 파일을 삭제해도 eclipse에서 오류가 발생하지 않는다. -->
		<failOnMissingWebXml>false</failOnMissingWebXml>
	</properties>
	<dependencies>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.45</version>
		</dependency>

		<!-- json 라이브러리 databind jackson-core, jackson-annotaion에 의존성이 있다. -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.9.4</version>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

pom.xml

 

 

 

package kr.or.connect.webapiexam.api;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

import kr.or.connect.jdbcRole.dao.RoleDao;
import kr.or.connect.jdbcRole.dto.Role;


@WebServlet("/roles")
public class RoleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public RoleServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json");		// 

		RoleDao dao = new RoleDao();

		List<Role> list = dao.getRoles();
		
		// json 패키지가 제공 : json문자열로 바꾸거나, json문자열을 객체로 바꾸어줌
		ObjectMapper objectMapper = new ObjectMapper();
		String json = objectMapper.writeValueAsString(list);
		
		PrintWriter out = response.getWriter();
		out.println(json);
		out.close();
	}

}

 RoleServlet.java

 

 

 

 

 

 

 

 

 

 

7. Web API 실습 코드 2

 

package kr.or.connect.webapiexam.api;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

import kr.or.connect.jdbcRole.dao.RoleDao;
import kr.or.connect.jdbcRole.dto.Role;


@WebServlet("/roles/*")			// 어떤 문자든지 올 수 있다.
public class RoleByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public RoleByIdServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json");

		String pathInfo = request.getPathInfo(); // /roles/{roleId}
		String[] pathParts = pathInfo.split("/");
		String idStr = pathParts[1];
		int id = Integer.parseInt(idStr);

		RoleDao dao = new RoleDao();

		Role role = dao.getRole(id);

		ObjectMapper objectMapper = new ObjectMapper();
		String json = objectMapper.writeValueAsString(role);

		PrintWriter out = response.getWriter();
		out.println(json);
		out.close();
		
	}

}

RoleByIdServlet.java

 

 

 

 

 

-> url 의 정보를 가져와서 roleId 가 501 번인 정보를 가져와서 json 형식으로 출력한다.

 

 

이처럼 JDBC와 서블릿을 이용해서 직접 API 를 만드는 경우는 매우 드물다.

대부분 Spring Framework 에서 API를 작성한다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형

+ Recent posts