svn freebook

svn 2005. 5. 30. 09:55

http://svnbook.red-bean.com/en/1.0/index.html

프리북이다.

개인적으로 너무 산만하게 구성한 거 같아서.. index 로 찾는거 외엔 안함.. 쩝..

'svn' 카테고리의 다른 글

svn 명령시 깨지는 글자나 나타날 때.  (0) 2005.11.01
http://www.abbeyworkshop.com/howto/misc/svn01/  (0) 2005.06.10
tip) 파일 하나만 Rep에서 가져오기  (0) 2005.05.30
TortoiseSVN  (0) 2005.05.30
svn getting started with svn  (0) 2005.05.30
Posted by '김용환'
,

하나의 파일을 가져오기 위해서, checkout을 쓰는 경우가 있다.

checkout은 Repository의 directoy를 통째로 가져오는 것이다.

$ svn co http://211.1.1.1/svn/goo/trunk/allis/module.lst

subversion/libsvn_client/checkout.c:99: (apr_err=200007)
svn: URL http://211.1.1.1/svn/goo/trunk/allis/module.lst' refers to a file, not a directory

$ ls module.lst
ls: malyon.el: No such file or directory

 

이럴때는 svn 새버젼을 다운받는다 ㅡ.ㅡ;; (아직 안나왔음... svn co의 최소한의 단위는 디렉토리임)

 

svn cat 을 이용해야함

'svn' 카테고리의 다른 글

svn 명령시 깨지는 글자나 나타날 때.  (0) 2005.11.01
http://www.abbeyworkshop.com/howto/misc/svn01/  (0) 2005.06.10
svn freebook  (0) 2005.05.30
TortoiseSVN  (0) 2005.05.30
svn getting started with svn  (0) 2005.05.30
Posted by '김용환'
,

TortoiseSVN

svn 2005. 5. 30. 09:38

http://www.mind.ilstu.edu/research/robots/iris/iris4/developers/svntutorial/

TortoiseSVN Tutorial 이다.

 

CVS에 이어. Tortoise는 윈도우에서 svn control이 가능한 프로그램을 내어놓았다.

뛰어난 성능에 감탄한다.. 아주 잘 쓰고 있다.

'svn' 카테고리의 다른 글

svn 명령시 깨지는 글자나 나타날 때.  (0) 2005.11.01
http://www.abbeyworkshop.com/howto/misc/svn01/  (0) 2005.06.10
svn freebook  (0) 2005.05.30
tip) 파일 하나만 Rep에서 가져오기  (0) 2005.05.30
svn getting started with svn  (0) 2005.05.30
Posted by '김용환'
,

svn getting started with svn

svn 2005. 5. 30. 09:36

간단한 설명, 개인적으로 freebook은 별로 맘에 들지 않는다.

Getting Started with SVN -- A Subversion Tutorial

Author: steven
Category: Tutorial
Written: January 03rd 2005
A couple years ago my friend and I were using CVS for version control on his server. I remember it took awhile to get CVS going, as I had to edit xinetd and set some permissions up. During development, we suffered--perhaps through our own fault--data corruption. Most notably, our image files for some of the project's icons got messed up.

That server crashed and burned sometime later. When it came to deciding what to go with the next time around, I stumbled on Subversion.

As Subversion had grown out of the frustrations and limitations of CVS, it seemed a natural replacement. The command line usage looked similar, so the learning curve wouldn't be too rough.

The first thing you need to do is create a Subversion repository. This is done through the svnadmin tool:

>svnadmin create svn-repository


Now you'll have a repository, which is really just a folder with some folders with names like conf, dav, db, hooks, and locks.

I should note that as of Subversion 1.1, there is a new type of storage backend. Traditionally, Subversion has relied on BerkeleyDB, but you can specifiy the newer--and perhaps less error-prone--filesystem backend at repository creation time. To use the FSFS (filesystem) backend, create your repository like this:

>svnadmin create --fs-type fsfs svn-repository


My first few repositories were BerkeleyDB-based, but I had some problems with my setup and the FSFS backend has proved much less of a pain, being less sensitive to permissions and multiple access methods.

Now that you have your repository, you probably want to import a project. Try this if you want your project to have its own directory within the repository:

>svn import project file:///path/to/svn-repository/project -m "comments"

In the above command, the first project refers to the directory of your project. The project at the end of the file:/// URL refers to what you want the project to be called within the repository (so it can be different).

The -m allows you to specifiy a message about this initial import. Now, within your svn-repository directory you'll have a project by the name of project (obviously change these names to something you like).

To check this project out, you'd type this:

>svn checkout file:///path/to/svn-repository/project local-name

This will dump the project into a folder called local-name. This is now your working copy. It contains code you can read and edit.

If you want multiple projects in your repository, add them as you did above, specifying a new project name for each one. Then you could check them out separately like this:

>svn checkout file:///path/to/svn-repository/prj1 prj1
>svn checkout file:///path/to/svn-repository/prj2 prj2
>svn checkout file:///path/to/svn-repository/prj3 prj3


The catch here is that Subversion does version numbering on a per-repository basis. This means that if you edit and commit to prj2, then the next checkout of, say, prj3 will share that same revision number. There's nothing wrong with this, but if you're like me you'll want a separate revision number for each project.

For that, use separate repositories for each project. For example, say I had a project called blur6ex and one called Advocate:

>svnadmin create file:///usr/svn/blur6ex
>svnadmin create file:///usr/svn/Advocate

>svn import /home/code/blur6ex file:///usr/svn/blur6ex -m "initial"
>svn import /home/code/Advocate file:///usr/svn/Advocate -m "initial"


Now I can check each one out separately and the versions are different for each project. It's not like there's any overhead for this.

Now some quick command to get started with these repositories.

To do a checkout:
svn checkout file:///usr/svn/blur6ex blur6


To commit (from your working copy directory):
svn commit -m "list changes here"



I need to go look at my httpd.conf setup to show you how to access these repositories in ways other than the file:/// urls.

One of Subversion's coolest features is the free book that guides you through everything.

 

http://www.romej.com/index.php?shard=content&action=g_viewContent&ID=12

 

'svn' 카테고리의 다른 글

svn 명령시 깨지는 글자나 나타날 때.  (0) 2005.11.01
http://www.abbeyworkshop.com/howto/misc/svn01/  (0) 2005.06.10
svn freebook  (0) 2005.05.30
tip) 파일 하나만 Rep에서 가져오기  (0) 2005.05.30
TortoiseSVN  (0) 2005.05.30
Posted by '김용환'
,

long milliseconds;
int seconds = (milliseconds/1000)%60;
int minutes = (milliseconds/60000)%60;

int hours = (milliseconds/3600000)%24;
int days = milliseconds/(24*60*60*1000);

의외로 많이 써서..

산수는 의외로 귀찮다구..

'java core' 카테고리의 다른 글

[TIP]자바 실행, 컴파일때 shell 이용법  (0) 2005.06.11
Runtime  (0) 2005.06.06
java 5.0 enum.  (0) 2005.05.12
jdk 5.0 static import test code  (0) 2005.05.11
jdk 5.0 Annotation, Enum Test code  (0) 2005.05.11
Posted by '김용환'
,

java 5.0 enum.

java core 2005. 5. 12. 19:04

java 의 enum은 컴파일러가 지원하는 primitive 타입이 아니라 컴파일러가 클래스로 변환시킨다.
Enum 클래스를 상속받은 static final class로서, 내부 요소들은 해당 클래스의 인스턴스를 가진다.

public class EnumType {
    public enum Editor {A1, A2};
    public static void main(String[] args) {
        System.out.println(Editor.A1);
    }
}

jad로 변환시키니, 다음과 같이 나왔다.


// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) fieldsfirst nonlb space
// Source File Name:   EnumType.java

import java.io.PrintStream;

public class EnumType {
    public static final class Editor extends Enum {

        public static final Editor A1;
        public static final Editor A2;
        private static final Editor $VALUES[];

        public static final Editor[] values() {
            return (Editor[])$VALUES.clone();
        }

        public static Editor valueOf(String s) {
            return (Editor)Enum.valueOf(EnumType$Editor, s);
        }

        static  {
            A1 = new Editor("A1", 0);
            A2 = new Editor("A2", 1);
            $VALUES = (new Editor[] {
                A1, A2
            });
        }

        private Editor(String s, int i) {
            super(s, i);
        }
    }


    public EnumType() {
    }

    public static void main(String args[]) {
        System.out.println(Editor.A1);
    }
}

'java core' 카테고리의 다른 글

Runtime  (0) 2005.06.06
millisecond를 가지고 구하기  (0) 2005.05.13
jdk 5.0 static import test code  (0) 2005.05.11
jdk 5.0 Annotation, Enum Test code  (0) 2005.05.11
jdk 5.0 Annotation Test Code  (0) 2005.05.11
Posted by '김용환'
,

import static java.lang.Math.*;
import static a.StaticImportTest.*;
public class StaticImport {
    public static void main(String[] args) {
        System.out.println(print());
    }
}

 

주의할 점은 import static이라는 점과, 항상 클래스뒤에 필드, 메소드를 의미한다는 의미로 해석해야한다는 것이다.

import static java.lang.Math.*;

이 문장은 Math 클래스의 static 필드, 메소드를 바로 호출 할 수 있다는 의미이다.

'java core' 카테고리의 다른 글

millisecond를 가지고 구하기  (0) 2005.05.13
java 5.0 enum.  (0) 2005.05.12
jdk 5.0 Annotation, Enum Test code  (0) 2005.05.11
jdk 5.0 Annotation Test Code  (0) 2005.05.11
[펌] RMI(Remote Method Invocation)  (0) 2005.05.11
Posted by '김용환'
,

자바 5.0의 Enum, Annotation Test Code이다.

실행결과는 따로 적지 않았다. 대충 만든거라, 약간 어설플 수도 있다.

 


import java.lang.annotation.*;
import java.lang.reflect.*;

@Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @interface debug {
    boolean devbuild() default false;
    int counter();
}

@Retention(RetentionPolicy.RUNTIME)
@interface Java {
    String value();
}

@Retention(RetentionPolicy.RUNTIME)
@interface  ID {
    String value();
}

@Retention(RetentionPolicy.RUNTIME)
@interface Desc {
    String value();
}

@ID("1")
public class MetaTest {

    @Java("123712831783")
    public String a;

    /*
    public enum Type {
        E1("aa"), E2("bb");
        private final String value;
        Type(String value) { this.value = value; }
        public String value() { return value; }
    }
    public Type xType = Type.E1;
    */
    public enum DescEnum {  X1,  X2 };
    public DescEnum de = DescEnum.X1;

    public void de(DescEnum m) {
        if (DescEnum.X1.equals(m)) {
            System.out.println("changed X1");
        } else {
            System.out.println("changed X2");
        }
    }
    /*final boolean production = true;
    @debug(devbuild = production, counter=1) public void testMethod() {}

    public MetaTest() {
        System.out.println(this);
    }*/

    public static void main(String[] args) {
        MetaTest mt = new MetaTest();
        ///////////////////////////////////////////////////////////////
        // de 필드에 enum element의 특정값 넣기.?
        ///////////////////////////////////////////////////////////////

        try {
            Field field = mt.getClass().getField("de");
            System.out.println(field.getType());
            Class cls = field.getType();
            if (cls.isEnum()) {
                System.out.println("c");
            }
            Method method = cls.getMethod("valueOf", String.class);
            Object o = method.invoke(cls, new Object[] { "X2" });
            System.out.println("name : f.getName() : " + o);
            field.set(mt, o);
            System.out.println("result : " + mt.de);

            //------------------------------------------------------
            Method method2 = mt.getClass().getMethod("de", cls);
            Class cls2 = method2.getParameterTypes()[0];
            System.out.println("oj : " + cls2);
            if (cls2.isEnum()) {
                System.out.println("xx");
                Method mtd = cls2.getMethod("valueOf", String.class);
                Object o2 = mtd.invoke(cls2, new Object[] { "X1" });
                System.out.println("o : " + o2);
                method2.invoke(mt, o2);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        ///////////////////////////////////////////////////////////////
        // 
        ///////////////////////////////////////////////////////////////

        /*
        ///////////////////////////////////////////////////////////////
        //  de 필드를 통해서 해당 값이 어떤것인지 알아오기.
        ///////////////////////////////////////////////////////////////

        try {
            Field field = mt.getClass().getField("de");
            System.out.println(field.getType());

            Class cls = field.getType();
            Field f = cls.getField("X1");
            Annotation a = f.getAnnotation(Desc.class);
            Method[] methods = a.getClass().getMethods();

            System.out.println(a);

            for (Method method : methods) {
                if (method.getName().equals("value")) {
                    System.out.println("**************find************");
                    try {
                        Object val = method.invoke(a, new Object[0]);
                        System.out.println("value: " + val);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }*/
        ///////////////////////////////////////////////////////////////
        //
        ///////////////////////////////////////////////////////////////

        /*try {
            Annotation[] a =
                mt.getClass().getMethod("testMethod").getAnnotations();
            for (int i = 0 ; i < a.length ; i++) {
                System.out.println("a[" + i + "]" + a[i]);
            }

        } catch (NoSuchMethodException e) {
            System.out.println(e);
        }
        String id = "1";
        System.out.println(id == "" ? "" : "2");

        Annotation ab = mt.getClass().getAnnotation(ID.class);
        System.out.println(ab);
        System.out.println("11");
        Field[] f = mt.getClass().getFields();
        System.out.println("22");
        Annotation a = f[0].getAnnotation(Java.class);
        Method[] methods = a.getClass().getMethods();
        System.out.println("num : " + methods.length);

        for (Method i : methods) {Type
            System.out.println("method = " + i.getName());
            //System.out.println("methods : " + i);

            if (i.getName().equals("value")) {
                System.out.println("**************find************");
                try {
                    Object val = i.invoke(a, new Object[0]);
                    System.out.println("value: " + val);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.out.println(a.toString()) ;
        System.out.println(a.value());

        Package p = mt.getClass().getPackage();
        System.out.println("aaa : " + p);
        try {
            Field field = mt.getClass().getField("a");
            System.out.println(field.getType());
            if (field.getType() == String.class) {
                System.out.println("equals to String");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } */

 

    }
}

 

'java core' 카테고리의 다른 글

java 5.0 enum.  (0) 2005.05.12
jdk 5.0 static import test code  (0) 2005.05.11
jdk 5.0 Annotation Test Code  (0) 2005.05.11
[펌] RMI(Remote Method Invocation)  (0) 2005.05.11
jdk 5.0) In runtime, java compile.  (0) 2005.04.25
Posted by '김용환'
,

자바 5.0의 Annotation에 대한 샘플 예제를 만들어 보았다.

 

import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;

@Retention(RetentionPolicy.RUNTIME)
@interface Title {
    String value();
}
public class AnnotationTest {

    public enum DescEnum {  @Title("1") X1,  X2 , X3 };
    public static EnumSet<DescEnum> de = EnumSet.of(DescEnum.X1, DescEnum.X2);

    public static void main(String[] args) {
        AnnotationTest mt = new AnnotationTest();
        ///////////////////////////////////////////////////////////////
        // EnumSet
        ///////////////////////////////////////////////////////////////

        try {
            Field field = mt.getClass().getField("de");
            System.out.println(field.getGenericType()) ;
            ParameterizedType tv = (ParameterizedType) field.getGenericType();
            System.out.println(tv);
            System.out.println("rawtype : " + tv.getRawType());
            System.out.println("getOwnerType : " + tv.getOwnerType());
            System.out.println("getReal : " + tv.getActualTypeArguments());

            for (Type t : tv.getActualTypeArguments()) {
                System.out.println("t : " + t);
                //System.out.println("class name: " + c.getName());
                Field[] enumFields = ((Class)t).getFields();
                for (Field f : enumFields) {
                    System.out.println("enum element name : " + f.getName());
                }
            }

            Iterator iter = de.iterator();
            while(iter.hasNext()) {
                System.out.println(iter.next());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

실행결과

 

$ java AnnotationTest
java.util.EnumSet<AnnotationTest$DescEnum>
java.util.EnumSet<AnnotationTest$DescEnum>
rawtype : class java.util.EnumSet
getOwnerType : null
getReal : [Ljava.lang.reflect.Type;@66848c
t : class AnnotationTest$DescEnum
enum element name : X1
enum element name : X2
enum element name : X3
X1
X2

 

'java core' 카테고리의 다른 글

jdk 5.0 static import test code  (0) 2005.05.11
jdk 5.0 Annotation, Enum Test code  (0) 2005.05.11
[펌] RMI(Remote Method Invocation)  (0) 2005.05.11
jdk 5.0) In runtime, java compile.  (0) 2005.04.25
jar  (0) 2005.04.25
Posted by '김용환'
,

▣ RMI(Remote Method Invocation)
   - 분산 시스템 구축시 Socket 방식을 이용하는 것보다 간결하고 신속함
   - RPC(Remote Procedure Call) : 원격지의 함수 호출, C 언어에서 사용
   - CORBA의 분산 객체 시스템과 비슷(이기종 간의 분산 처리 구축, 코바서버를 2중으로 구축시 모든 서버에서 트랜잭션이 안정적으로 진행이 안됨)
   - 원리
                       Client Area ↓                ↓Server Area 
     -----------------------------------------------------------------------------------------
     Local System --> Class --> Stub --> NETWORK --> Stub --> Skeleton --> Class Remote System
                   결과전송 <-- Stub <-- NETWORK <----------- Skeleton <-- 비지니스 로직 처리                

 


1. RMI 프로그래밍 순서도
   ① 원격 인터페이스 정의
   ② 원격 객체 구현
   ③ javac 컴파일 - 원격 객체 클래스
   ④ rmic - Stub, Skeleton class 생성
   ⑤ 로컬 객체 클래스 제작  
   ⑤ RMI 등록 서버 실행
   ⑥ 클라이언트 접속

 


2. UnicastRemoteObject 의 상속 구조

     public abstract class RemoteObject extends Object implements Remote, Serializable
     --> java.lang.Object 클래스의 hashCode(), equals(), toString() 메소드를 구현해서 갖고 있는 클래스
     ↑
     public abstract class RemoteServer extends RemoteObject
     --> 원격지 메소드 참조에 대한 구현에 대한 FrameWork을 갖고 있는 최상위 클래스
     ↑
     public class UnicastRemoteObject extends RemoteServer
     -->  tcp 상에서 object reference를 참조할 수 있도록 지원해 주는 클래스

 


3. Echo 예제 실습
--------------------------------------------------------------------------
구분  CLIENT SIDE SERVER SIDE
--------------------------------------------------------------------------
Interface            Echo.class  Echo.class

Remote Object   EchoImpl.class

Proxy  EchoImpl_Stub.class EchoImpl_Stub/Skel.class

Run Class            EchoClient.class EchoServer.class
--------------------------------------------------------------------------
실행 순서
1. rmic EchoImp
2. start rmiregistry   <-- C:\Program Files\Oracle\jre\1.1.7\bin; 경로가 PATH에 있으면 제거하고 시스템 재 시작합니다.
3. java EchoServer
4. java EchoClient nulunggi


------------------------ e.bat ------------------------
rmic EchoImpl
start rmiregistry
rem ---------
rem 서버 작동
rem ---------
java EchoServer

 

1/4-------------------------- Echo.java --------------------------
import java.rmi.RemoteException;

import java.rmi.Remote;

public interface Echo extends Remote{
  public String sayEcho(String name) throws RemoteException;
}


2/4-------------------------- EchoImpl.java --------------------------
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class EchoImpl extends UnicastRemoteObject implements Echo{
 String message;

 public EchoImpl() throws RemoteException{}

 public EchoImpl(String message) throws RemoteException{
  this.message = message;
 }

 public String sayEcho(String name){
  return "\n 엄기흥 강사 PC 로 부터 전송된 문자열 : " + message + " " + name + "님 \n";
 }
}
 

3/4-------------------------- EchoServer.java --------------------------
import java.rmi.Naming;

public class EchoServer{
  public static void main(String args[]){
    try{
      EchoImpl echoRef = new EchoImpl();
      Naming.bind("Echo",echoRef);
    }catch( java.rmi.AlreadyBoundException e){
      e.printStackTrace();  
    }catch(java.net.MalformedURLException e ){
      e.printStackTrace();
    }catch( java.rmi.RemoteException e){
      e.printStackTrace();   
    }
    System.out.println("--------------------------------");
    System.out.println("Echo RMI 서버가 작동 되었습니다.");
    System.out.println("--------------------------------");
  }
}


4/4-------------------------- EchoClient.java --------------------------
import java.rmi.Naming;
import java.rmi.*;
import java.net.*;

public class EchoClient{
 public static void main(String args[]){
  String url = "rmi://127.0.0.1/Echo";
                     //String url = "rmi://" + args[0] + "/Echo";

  Echo echoRef = null;
  try{
   echoRef = (Echo)Naming.lookup(url);

   System.out.println(echoRef.sayEcho(args[0]));
  }catch(RemoteException e){
   e.printStackTrace();
  }catch(MalformedURLException e){
   e.printStackTrace();
  }catch(NotBoundException e){
   e.printStackTrace();
  }
  
 }
}

 


4. RMI 서버 모듈의 분리 예제
--------------------------------------------------------------------------
구분  CLIENT SIDE        SERVER SIDE
--------------------------------------------------------------------------
Interface            Echo.class         Echo.class
                      EchoFactory.class           EchoFactory.class

Remote Object          EchoImpl.class
                                                  EchoFactoryImpl.class 

Proxy  EchoImpl_Stub.class        EchoImpl_Stub/Skel.class
                     EchoFactoryImpl_Stub.class   EchoFactoryImpl_Stub/Skel.class

Run Class            EchoFactoryClient.class      EchoFactoryServer.class
Start File           s.bat                        r.bat
--------------------------------------------------------------------------


실행 방법 : r.bat
rem ---------------------------------------
rem 파일 내용 : Echo 예제 배치파일 입니다.
rem 작성일 : 2002-01-01
rem 작성자 : 엄기흥
rem ---------------------------------------
rmic EchoImpl
rmic EchoFactoryImpl
start rmiregistry.exe
java EchoFactoryServer

 


1/6------------------------ Echo.java ------------------------
import java.rmi.RemoteException;

import java.rmi.Remote;

public interface Echo extends Remote{
  public String sayEcho(String name) throws RemoteException;
}


2/6------------------------ EchoImpl.java ------------------------
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class EchoImpl extends UnicastRemoteObject implements Echo{
 String message;

 public EchoImpl() throws RemoteException{}

 public EchoImpl(String message) throws RemoteException{
  this.message = message;
 }

 public String sayEcho(String name){
  return "\n " + message + " " + name + "님 \n";
 }
}


3/6------------------------ EchoFactory.java ------------------------
import java.rmi.RemoteException;
import java.rmi.Remote;

public interface EchoFactory extends Remote{
  public Echo getEcho(String greeting) throws RemoteException;
}


4/6------------------------ EchoFactoryImpl.java ------------------------
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class EchoFactoryImpl extends UnicastRemoteObject implements EchoFactory{
 
  public EchoFactoryImpl() throws RemoteException{}

  public Echo getEcho(String message) throws RemoteException{
    EchoImpl echoRef = new EchoImpl(message);
    return (Echo)echoRef;
  }

}


5/6------------------------ EchoFactoryServer.java ------------------------
import java.rmi.Naming;

public class EchoFactoryServer {
 public static void main(String args[]) throws Exception{
  EchoFactoryImpl factoryRef = new EchoFactoryImpl();

  Naming.rebind("EchoFactory",factoryRef);
  
  System.out.println("서버가 시작되었습니다.");
 }
}


6/6------------------------ EchoFactoryClient.java ------------------------
import java.rmi.Naming;
import java.rmi.*;
import java.net.*;

public class EchoFactoryClient{
  public static void main(String args[]){
   
 //String url = "rmi://127.0.0.1/EchoFactory";

 EchoFactory ref = null;

 try{
  if (args.length != 2){
                        System.out.println("파라미터가 잘못되었습니다.");
   System.out.println("사용법 : java EchoFactoryClient nulunggi 211.108.242.114");
   System.exit(1);
  }

  ref = (EchoFactory)Naming.lookup("rmi://" + args[1] + "/EchoFactory");

  Echo echoHello = ref.getEcho("수고하셨습니다.");
  Echo echoGood = ref.getEcho("2개월간 고생하셨습니다.");

  System.out.println(echoHello.sayEcho(args[0])); 
  System.out.println(echoGood.sayEcho(args[0])); 

 }catch(RemoteException e){
  e.printStackTrace();  
 }catch(MalformedURLException e){
  e.printStackTrace(); 
 }catch(NotBoundException e){
  e.printStackTrace(); 
 }

  }
}

 


▣ RMI + Thread를 이용하여 여러 컴퓨터에서 계산하기

------------------------ e.bat ------------------------
rmic EchoImpl
start rmiregistry
rem ---------
rem 서버 작동
rem ---------
java EchoServer

 


1. 서버쪽 수정 EchoImpl.java

1/4-------------------------- Echo.java --------------------------
import java.rmi.RemoteException;

import java.rmi.Remote;

public interface Echo extends Remote{
  public String sayEcho(String name) throws RemoteException;
}


2/4-------------------------- EchoImpl.java --------------------------
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class EchoImpl extends UnicastRemoteObject implements Echo{
 String message;

 public EchoImpl() throws RemoteException{}

 public EchoImpl(String message) throws RemoteException{
  this.message = message;
 }

 public String sayEcho(String name){

             int i=1;
             long hap=0;

             for(long q=1; q<=500000000; q++){
                       hap = hap + q;
             }
    return i + "번째 1부터 500,000,000까지의 합 : " + hap + "\n";

 }
}
 

3/4-------------------------- EchoServer.java --------------------------
import java.rmi.Naming;

public class EchoServer{
  public static void main(String args[]){
    try{
      EchoImpl echoRef = new EchoImpl();
      Naming.bind("Echo",echoRef);
    }catch( java.rmi.AlreadyBoundException e){
      e.printStackTrace();  
    }catch(java.net.MalformedURLException e ){
      e.printStackTrace();
    }catch( java.rmi.RemoteException e){
      e.printStackTrace();   
    }
    System.out.println("--------------------------------");
    System.out.println("Thread용 Echo RMI 서버가 작동 되었습니다.");
    System.out.println("--------------------------------");
  }
}


4/4-------------------------- EchoClient.java --------------------------
import java.rmi.Naming;
import java.rmi.*;
import java.net.*;

public class EchoClient{
 public static void main(String args[]){
  String url = "rmi://127.0.0.1/Echo";
                     //String url = "rmi://" + args[0] + "/Echo";

  Echo echoRef = null;
  try{
   echoRef = (Echo)Naming.lookup(url);

   System.out.println(echoRef.sayEcho(args[0]));
  }catch(RemoteException e){
   e.printStackTrace();
  }catch(MalformedURLException e){
   e.printStackTrace();
  }catch(NotBoundException e){
   e.printStackTrace();
  }
  
 }
}

 

2. 클라이언트쪽
------------------------ EchoClientThread.java -------------------
/***********************************
파일명:
작성자: 엄기흥
최종 수정일: 20020308-2102
파일 내용: 자바 수업 중에 테스트 한 파일
************************************/
import java.rmi.Naming;
import java.rmi.*;
import java.net.*;

public class EchoClientThread extends Thread{
 String ip=null;
 Echo echoRef = null;

 EchoClientThread(String ip){
     this.ip = ip;
 }

 public void run(){
  try{
   String url = "rmi://" + ip + "/Echo";
   echoRef = (Echo)Naming.lookup(url);
   System.out.println(echoRef.sayEcho("누룽지"));

  }catch(RemoteException e){
   e.printStackTrace();
  }catch(MalformedURLException e){
   e.printStackTrace();
  }catch(NotBoundException e){
   e.printStackTrace();
  }

 }

 public static void main(String args[]){
  EchoClientThread e67, e74, e76, e78, e98, e72, e69;
  

  e67 = new EchoClientThread("211.108.242.106");
  e74 = new EchoClientThread("211.108.242.107");
  e76 = new EchoClientThread("211.108.242.109");
  e78 = new EchoClientThread("211.108.242.110");
  e98 = new EchoClientThread("211.108.242.108");
  e72 = new EchoClientThread("211.108.242.112");
  e69 = new EchoClientThread("211.108.242.114");

  e67.start();
  e74.start();
  e76.start();
  e78.start();
  e98.start();
  e72.start();
  e69.start();
 }
}

 

------------------------ EchoClientThread1.java -------------------
/***********************************
파일명:
작성자: 엄기흥
최종 수정일: 20020308-2102
파일 내용: 자바 수업 중에 테스트 한 파일
************************************/
import java.rmi.Naming;
import java.rmi.*;
import java.net.*;

public class EchoClientThread1 extends Thread{
 String ip=null;
 Echo echoRef = null;
 
 EchoClientThread1(String ip){
     this.ip = ip;
 }

 public void run(){
  try{
   if(ip.equals("67")){
    String url = "rmi://211.108.242.114/Echo";
    echoRef = (Echo)Naming.lookup(url);
    System.out.println(echoRef.sayEcho("누룽지"));
   }else if(ip.equals("74")){
    String url = "rmi://211.108.242.106/Echo";
    echoRef = (Echo)Naming.lookup(url);
    System.out.println(echoRef.sayEcho("누룽지"));
   }else if(ip.equals("76")){
    String url = "rmi://211.108.242.107/Echo";
    echoRef = (Echo)Naming.lookup(url);
    System.out.println(echoRef.sayEcho("누룽지"));
   }else if(ip.equals("78")){
    String url = "rmi://211.108.242.109/Echo";
    echoRef = (Echo)Naming.lookup(url);
    System.out.println(echoRef.sayEcho("누룽지"));
   }else if(ip.equals("98")){
    String url = "rmi://211.108.242.110/Echo";
    echoRef = (Echo)Naming.lookup(url);
    System.out.println(echoRef.sayEcho("누룽지"));
   }else if(ip.equals("72")){
    String url = "rmi://211.108.242.111/Echo";
    echoRef = (Echo)Naming.lookup(url);
    System.out.println(echoRef.sayEcho("누룽지"));
   }else if(ip.equals("69")){
    String url = "rmi://211.108.242.112/Echo";
    echoRef = (Echo)Naming.lookup(url);
    System.out.println(echoRef.sayEcho("누룽지"));
   }

  }catch(RemoteException e){
   e.printStackTrace();
  }catch(MalformedURLException e){
   e.printStackTrace();
  }catch(NotBoundException e){
   e.printStackTrace();
  }

 }

 public static void main(String args[]){
  EchoClientThread1 e67, e74, e76, e78, e98, e72, e69;
  

  e67 = new EchoClientThread1("67");
  e74 = new EchoClientThread1("74");
  e76 = new EchoClientThread1("76");
  e78 = new EchoClientThread1("78");
  e98 = new EchoClientThread1("98");
  e72 = new EchoClientThread1("72");
  e69 = new EchoClientThread1("69");

  e67.start();
  e74.start();
  e76.start();
  e78.start();
  e98.start();
  e72.start();
  e69.start();
 }
}

'java core' 카테고리의 다른 글

jdk 5.0 Annotation, Enum Test code  (0) 2005.05.11
jdk 5.0 Annotation Test Code  (0) 2005.05.11
jdk 5.0) In runtime, java compile.  (0) 2005.04.25
jar  (0) 2005.04.25
Runtime in jdk5.0  (0) 2005.03.26
Posted by '김용환'
,