かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

Java RMIのHelloWorld

かなり枯れた?技術だけど手をつけてないものにJavaのRMIってのがある。
要はリモート呼び出し。

Javaからしか呼べないけど、SOAPとかそこらへんの汎用的なものより早いのが多分売り。
なので、これをちょいと試して見る。
開発環境は、Java SE6 + NetBeans6 beta1です。

サーバー側のプログラム作成

サーバー側のプログラムは、まずインターフェースを作らないといけない。
守らなきゃいけないのは、以下の2つ。

  1. java.rmi.Remoteを継承する
  2. メソッドはjava.rmi.RemoteExceptionをスローする

これを守って書くと↓のようになる。

package kazuki.rmi;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface HelloWorld extends Remote {
    String sayHelloWorld() throws RemoteException;
}

 

次は、これの実装クラスを書く。
実装クラスは、当然↑で定義したインターフェースを実装するんだけど、気を付けないといけないことが2つある。

  1. java.rmi.server.UnicastRemoteObjectを継承する
  2. throws java.rmi.RemoteExceptionのついたコンストラクタを用意する

これを守って書くと↓のようになる。

package kazuki.rmi;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class HelloWorldImpl extends UnicastRemoteObject implements HelloWorld {

    public HelloWorldImpl() throws RemoteException {
        super();
    }
    public String sayHelloWorld() throws RemoteException {
        return "Hello world";
    }

}

 

最後に、これをリモートで呼び出せるように登録をするプログラムを書く。
ググった感じだと、rmiregistryをコマンドラインから起動してNamingクラスを使うよ~って書いてあるけど、うちじゃ頑張ったけどうまくいかなかった。
なので、java.rmi.LocateRegistryを使った。
createRegistryで作ってbindで登録する。コードは↓のとおり。

package kazuki.rmi;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RmiServer {

    public static void main(String[] args) throws Exception {
        Registry reg = LocateRegistry.createRegistry(1099);
        reg.bind("HelloWorld", new HelloWorldImpl());
    }
}

 

クライアント側プログラム

クライアント側プログラムは、Registryから目的のブツをゲットして呼び出すだけ。
さくっと書いてしまおう。

package kazuki.client;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import kazuki.rmi.HelloWorld;

public class RmiClient {
    public static void main(String[] args) throws Exception {
        Registry reg = LocateRegistry.getRegistry(1099);
        HelloWorld helloWorld = (HelloWorld) reg.lookup("HelloWorld");
        System.out.println(helloWorld.sayHelloWorld());
    }

}

 

getRegistryで、Registryを取得。その後lookupで呼び出したいブツをゲット。
後は普通にクラスを使う要領で使ってやればいい。

NetBeans6から、起動構成?を複数作れるから、サーバ側とクライアント側の起動を簡単に切りかえれて便利になった。

image image

投稿日時 : 2007年9月23日 11:27

Feedback

# re: Java RMIのHelloWorld 2007/09/23 17:01 かつのり

RMIだとAPIが低レベル過ぎて面倒ですよね。
最近はリモート処理をやる為にJMXを使っています。
JMXは管理用APIとはいえ、リモート処理のフレームワークでもあります。

J2EEサーバ等でもJMXに対応したものが多いので、
慣れると結構広く使えて便利ですよ。

# re: Java RMIのHelloWorld 2007/09/23 22:14 かずき

お~興味あります!
MXBeanを作って登録してごにょごにょって所くらいまでは今やってみました。
MXBeanがサーバ側になるんですよね?多分…
クライアント側の作り方が未だわからずですorz

# JMXをリモート呼び出しのために使ってみる 2007/09/23 23:01 かずきのBlog

JMXをリモート呼び出しのために使ってみる

# re: Java RMIのHelloWorld 2009/01/06 16:10 test

Callback ってどうやるのでしょうか?

# sacs lancel 2012/10/19 16:00 http://www.saclancelpascher2013.com

As soon as I observed this site I went on reddit to share some of the love with them.

# Nike Air Jordan High Heels 2012/12/08 4:54 http://suparjordanshoes1.webs.com/

Thanks for the sensible critique. Me and my neighbor were just preparing to do some research on this. We got a grab a book from our area library but I think I learned more clear from this post. I'm very glad to see such wonderful info being shared freely out there.

# moncler coats 2012/12/08 8:08 http://supermonclercoats.webs.com/

Its great as your other articles : D, regards for posting . "It takes less time to do things right than to explain why you did it wrong." by Henry Wadsworth Longfellow.

# トリーバーチ 靴 2012/12/14 22:36 http://www.torybruchjp.info

If your current photostream contains photos who - no matter if good or not : triggered some sort of spirited comments¡ä bond.

# sac pliage longchamp 2012/12/16 21:14 http://www.sacslongchamp2012.info/pliage-longchamp

we re-watched our creator of the actual Rings trilogy, the Godfather trilogy, and regarding twenty some other movies that people loved and also hadn¡¯t watched in the while.

# sacs longchamps 2012/12/17 20:30 http://www.sacslongchamp2012.info/le-pliage-longch

I guess I'm sure not on your own having many of the enjoyment in this article!

# sacs michael kors 2012 2012/12/18 19:55 http://sac2012femmes.wordpress.com

I implement earbuds away from home because with their portability, even though I prefer over typically the ear.

# isabel marant sortie paris 2012/12/18 20:31 http://www.isabelmarant-stores.com/category/isabel

I are in agreement with the expensive garbage remark. I dislike the glance, sound or perhaps feel of your Beats.

# Burberry sortie 2012/12/19 13:29 http://sacburberrysoldesfr.webnode.fr/actualites

gripping avenues of opinions bursting away from your photos.

# Michael Kors outlet 2012/12/21 3:00 http://sac-michael-kors.webnode.fr

Great blog post, it's beneficial information.

# destockchine 2013/01/10 22:48 http://www.destockchinefr.fr/nike-shox-pas-cher/ni

Don't make friends might be luxurious to be with. It's the perfect time that will stress someone to prise your spouse right up.
destockchine http://www.destockchinefr.fr/nike-shox-pas-cher/nike-shox-nz-2-pas-cher/

# re: Java RMIのHelloWorld 2013/03/02 18:47 Zdeno Chara Jersey

http://www.bruinsstoreonline.com/zdeno_chara_jersey Zdeno Chara Jersey
http://www.bruinsstoreonline.com/tyler_seguin_jersey Tyler Seguin Jersey
http://www.bruinsstoreonline.com/milan_lucic_jersey Milan Lucic Jersey
http://www.bruinsstoreonline.com/tim_thomas_jersey Tim Thomas Jersey
http://www.bruinsstoreonline.com/patrice_bergeron_jersey Patrice Bergeron Jersey
http://www.bruinsstoreonline.com/brad_marchand_jersey Brad Marchand Jersey
http://www.bruinsstoreonline.com/bobby_orr_jersey Bobby Orr Jersey
http://www.bruinsstoreonline.com/cam_neely_jersey Cam Neely Jersey
http://www.bruinsstoreonline.com/nathan_horton_jersey Nathan Horton Jersey

# FAWRHlSaKrOpYxDT 2014/08/05 5:30 http://crorkz.com/

Be14gH Thanks again for the blog post.

# VjuSeoZenwdymPbVf 2014/08/28 10:08 http://crorkz.com/

JJC9vd Useful info. Lucky me I discovered your website unintentionally, and I am surprised why this coincidence didn't came about in advance! I bookmarked it.

# euVdokFlzux 2014/08/30 23:42 https://www.youtube.com/watch?v=CX-BtyBKO8Q

Well I sincerely liked reading it. This post procured by you is very practical for correct planning.

# NBPWXqZWjTdx 2014/09/09 19:12 http://www.arrasproperties.com/4009-e-3rd-st-apt-3

This website is really a walk-by for all of the information you wished about this and didn't know who to ask. Glimpse right here, and you'll positively discover it.

# Excellent beat ! I would like to apprentice while you amend your website, how could i subscribe for a blog web site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear concept 2018/09/17 10:08 Excellent beat ! I would like to apprentice while

Excellent beat ! I would like to apprentice while you amend your website, how could i subscribe for a blog web site?
The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear concept

# Hi there everybody, here every person is sharing these knowledge, therefore it's fastidious to read this blog, and I used to go to see this webpage all the time. 2018/09/18 22:33 Hi there everybody, here every person is sharing t

Hi there everybody, here every person is sharing these
knowledge, therefore it's fastidious to read this blog, and I used to go to see this webpage all the time.

# Now I am going to do my breakfast, once having my breakfast coming yet again to read more news. 2018/10/01 23:52 Now I am going to do my breakfast, once having my

Now I am going to do my breakfast, once having my breakfast
coming yet again to read more news.

# When some one searches for his essential thing, thus he/she wishes to be available that in detail, therefore that thing is maintained over here. 2018/10/02 9:26 When some one searches for his essential thing, th

When some one searches for his essential thing, thus he/she
wishes to be available that in detail, therefore that thing is maintained over here.

# It's perfect time to make a few plans for the long run and it's time to be happy. I've read this submit and if I may I desire to suggest you some fascinating things or advice. Maybe you could write next articles regarding this article. I want to learn e 2018/10/05 13:26 It's perfect time to make a few plans for the long

It's perfect time to make a few plans for the long run and
it's time to be happy. I've read this submit and if I may I
desire to suggest you some fascinating things or advice.
Maybe you could write next articles regarding this article.
I want to learn even more issues approximately it!

# Hi! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing many months of hard work due to no data backup. Do you have any solutions to prevent hackers? 2018/10/06 5:39 Hi! I just wanted to ask if you ever have any prob

Hi! I just wanted to ask if you ever have any
problems with hackers? My last blog (wordpress) was hacked and I ended up losing many months of hard work due to no data backup.
Do you have any solutions to prevent hackers?

# If some one wishes to be updated with most up-to-date technologies then he must be visit this web page and be up to date everyday. 2018/10/22 5:43 If some one wishes to be updated with most up-to-d

If some one wishes to be updated with most up-to-date technologies then he must be visit this web page and be up to date
everyday.

# GulmdcsnTB 2018/12/17 9:11 https://www.suba.me/

Qm5bZY This site was how do you say it? Relevant!! Finally I ave found something that helped me. Thanks!|

# eNatNrmHOOnQGAeYYNO 2018/12/20 0:38 https://www.suba.me/

mKC0QF Thanks again for the article.Much thanks again. Awesome.

# Hello to every one, since I am actually keen of reading this blog's post to be updated regularly. It carries fastidious stuff. 2019/03/29 18:57 Hello to every one, since I am actually keen of re

Hello to every one, since I am actually keen of reading this blog's
post to be updated regularly. It carries fastidious stuff.

# Hi there friends, its enormous article concerning teachingand completely explained, keep it up all the time. 2019/04/21 2:51 Hi there friends, its enormous article concerning

Hi there friends, its enormous article concerning
teachingand completely explained, keep it up all the time.

# This post will assist the internet users for building up new blog or even a blog from start to end. 2019/07/02 2:14 This post will assist the internet users for build

This post will assist the internet users for building up new blog or even a blog from start to end.

# Its like you read my thoughts! You appear to know so much approximately this, like you wrote the e book in it or something. I believe that you just can do with some percent to pressure the message home a bit, however instead of that, that is great blog. 2021/08/23 15:07 Its like you read my thoughts! You appear to know

Its like you read my thoughts! You appear to know so much
approximately this, like you wrote the e book in it or something.
I believe that you just can do with some percent to pressure the message home a
bit, however instead of that, that is great blog.

A great read. I'll definitely be back.

# Its like you read my thoughts! You appear to know so much approximately this, like you wrote the e book in it or something. I believe that you just can do with some percent to pressure the message home a bit, however instead of that, that is great blog. 2021/08/23 15:08 Its like you read my thoughts! You appear to know

Its like you read my thoughts! You appear to know so much
approximately this, like you wrote the e book in it or something.
I believe that you just can do with some percent to pressure the message home a
bit, however instead of that, that is great blog.

A great read. I'll definitely be back.

# Its like you read my thoughts! You appear to know so much approximately this, like you wrote the e book in it or something. I believe that you just can do with some percent to pressure the message home a bit, however instead of that, that is great blog. 2021/08/23 15:09 Its like you read my thoughts! You appear to know

Its like you read my thoughts! You appear to know so much
approximately this, like you wrote the e book in it or something.
I believe that you just can do with some percent to pressure the message home a
bit, however instead of that, that is great blog.

A great read. I'll definitely be back.

# Its like you read my thoughts! You appear to know so much approximately this, like you wrote the e book in it or something. I believe that you just can do with some percent to pressure the message home a bit, however instead of that, that is great blog. 2021/08/23 15:10 Its like you read my thoughts! You appear to know

Its like you read my thoughts! You appear to know so much
approximately this, like you wrote the e book in it or something.
I believe that you just can do with some percent to pressure the message home a
bit, however instead of that, that is great blog.

A great read. I'll definitely be back.

# First off I would like to say wonderful blog! I had a quick question in which I'd like to ask if you do not mind. I was curious to know how you center yourself and clear your thoughts prior to writing. I've had a tough time clearing my mind in getting my 2021/08/25 21:34 First off I would like to say wonderful blog! I ha

First off I would like to say wonderful blog!

I had a quick question in which I'd like to ask if you do not mind.
I was curious to know how you center yourself and clear your thoughts prior to writing.
I've had a tough time clearing my mind in getting
my thoughts out. I do enjoy writing however it just
seems like the first 10 to 15 minutes are wasted simply
just trying to figure out how to begin. Any recommendations or tips?
Cheers!

# Appreciate the recommendation. Let me try it out. 2021/08/26 6:51 Appreciate the recommendation. Let me try it out.

Appreciate the recommendation. Let me try it out.

# You ought to be a part of a contest for one of the best websites on the web. I'm going to recommend this site! 2021/08/31 20:04 You ought to be a part of a contest for one of the

You ought to be a part of a contest for one of the best websites on the web.
I'm going to recommend this site!

# I couldn't resist commenting. Exceptionally well written! 2021/09/01 19:19 I couldn't resist commenting. Exceptionally well w

I couldn't resist commenting. Exceptionally well written!

# I couldn't resist commenting. Exceptionally well written! 2021/09/01 19:20 I couldn't resist commenting. Exceptionally well w

I couldn't resist commenting. Exceptionally well written!

# I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome article. 2021/09/03 20:28 I read this post completely about the comparison o

I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome
article.

# I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome article. 2021/09/03 20:29 I read this post completely about the comparison o

I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome
article.

# I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome article. 2021/09/03 20:30 I read this post completely about the comparison o

I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome
article.

# I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome article. 2021/09/03 20:31 I read this post completely about the comparison o

I read this post completely about the comparison of most up-to-date and earlier technologies, it's awesome
article.

# After looking at a few of the blog posts on your web site, I really appreciate your way of blogging. I bookmarked it to my bookmark site list and will be checking back in the near future. Please visit my website too and tell me how you feel. 2021/09/04 18:19 After looking at a few of the blog posts on your w

After looking at a few of the blog posts on your web
site, I really appreciate your way of blogging. I bookmarked
it to my bookmark site list and will be checking back in the
near future. Please visit my website too and tell me how you feel.

# After looking at a few of the blog posts on your web site, I really appreciate your way of blogging. I bookmarked it to my bookmark site list and will be checking back in the near future. Please visit my website too and tell me how you feel. 2021/09/04 18:20 After looking at a few of the blog posts on your w

After looking at a few of the blog posts on your web
site, I really appreciate your way of blogging. I bookmarked
it to my bookmark site list and will be checking back in the
near future. Please visit my website too and tell me how you feel.

# After looking at a few of the blog posts on your web site, I really appreciate your way of blogging. I bookmarked it to my bookmark site list and will be checking back in the near future. Please visit my website too and tell me how you feel. 2021/09/04 18:21 After looking at a few of the blog posts on your w

After looking at a few of the blog posts on your web
site, I really appreciate your way of blogging. I bookmarked
it to my bookmark site list and will be checking back in the
near future. Please visit my website too and tell me how you feel.

# After looking at a few of the blog posts on your web site, I really appreciate your way of blogging. I bookmarked it to my bookmark site list and will be checking back in the near future. Please visit my website too and tell me how you feel. 2021/09/04 18:22 After looking at a few of the blog posts on your w

After looking at a few of the blog posts on your web
site, I really appreciate your way of blogging. I bookmarked
it to my bookmark site list and will be checking back in the
near future. Please visit my website too and tell me how you feel.

# I was recommended this web site by way of my cousin. I am not certain whether this put up is written by him as no one else realize such designated about my difficulty. You are wonderful! Thanks! 2021/10/27 0:31 I was recommended this web site by way of my cous

I was recommended this web site by way of my cousin.
I am not certain whether this put up is written by him as
no one else realize such designated about my difficulty. You are wonderful!
Thanks!

# Magnificent website. Lots of useful info here. I am sending it to several pals ans also sharing in delicious. And of course, thanks in your effort! 2021/11/12 16:49 Magnificent website. Lots of useful info here. I a

Magnificent website. Lots of useful info here. I am sending
it to several pals ans also sharing in delicious.
And of course, thanks in your effort!

# Magnificent website. Lots of useful info here. I am sending it to several pals ans also sharing in delicious. And of course, thanks in your effort! 2021/11/12 16:50 Magnificent website. Lots of useful info here. I a

Magnificent website. Lots of useful info here. I am sending
it to several pals ans also sharing in delicious.
And of course, thanks in your effort!

# Magnificent website. Lots of useful info here. I am sending it to several pals ans also sharing in delicious. And of course, thanks in your effort! 2021/11/12 16:51 Magnificent website. Lots of useful info here. I a

Magnificent website. Lots of useful info here. I am sending
it to several pals ans also sharing in delicious.
And of course, thanks in your effort!

# Magnificent website. Lots of useful info here. I am sending it to several pals ans also sharing in delicious. And of course, thanks in your effort! 2021/11/12 16:52 Magnificent website. Lots of useful info here. I a

Magnificent website. Lots of useful info here. I am sending
it to several pals ans also sharing in delicious.
And of course, thanks in your effort!

# Hello! This is kind of off topic but I need some advice from an established blog. Is it difficult to set up your own blog? I'm not very techincal but I can figure things out pretty fast. I'm thinking about making my own but I'm not sure where to begin. 2021/12/24 5:33 Hello! This is kind of off topic but I need some a

Hello! This is kind of off topic but I need some advice from an established blog.
Is it difficult to set up your own blog? I'm not very techincal but
I can figure things out pretty fast. I'm thinking about making
my own but I'm not sure where to begin. Do you have any tips
or suggestions? Cheers

# Hi, everything is going well here and ofcourse every one is sharing facts, that's really excellent, keep up writing. 2022/03/23 18:17 Hi, everything is going well here and ofcourse eve

Hi, everything is going well here and ofcourse every
one is sharing facts, that's really excellent, keep up
writing.

# Hi, everything is going well here and ofcourse every one is sharing facts, that's really excellent, keep up writing. 2022/03/23 18:18 Hi, everything is going well here and ofcourse eve

Hi, everything is going well here and ofcourse every
one is sharing facts, that's really excellent, keep up
writing.

# Hi, everything is going well here and ofcourse every one is sharing facts, that's really excellent, keep up writing. 2022/03/23 18:19 Hi, everything is going well here and ofcourse eve

Hi, everything is going well here and ofcourse every
one is sharing facts, that's really excellent, keep up
writing.

# Hi, everything is going well here and ofcourse every one is sharing facts, that's really excellent, keep up writing. 2022/03/23 18:20 Hi, everything is going well here and ofcourse eve

Hi, everything is going well here and ofcourse every
one is sharing facts, that's really excellent, keep up
writing.

# ロレックスコピー 2023/06/04 18:08 coxAcquic

スーパーは時計をコピーしますブランド偽物、偽物ブランド、ルイヴィトンコピー、 ロレックスコピー、シャネルコピー、グッチコピー、エルメスコピー、 ボッテガヴェネタコピー、 バーバリーコピー、ミュウミュウコピー、トリーバーチコピー、バレンシアガコピー、ディオールコピー、ブルガリコピー、ブラダコピー、 ドルチェ&ガッバーナコピー、オメガコピー、フランク ミュラーコピー、gagaコピー。 }}}}}}
https://www.bagssjp.com/product/detail-9345.html
https://www.bagssjp.com/product/detail-11559.html
https://www.bagssjp.com/product/detail-817.html
https://www.bagssjp.com/product/detail-744.html
https://www.bagssjp.com/product/detail-6121.html

# ルイ ヴィトン 手帳 mm 2023/11/10 20:33 gzbxxti@live.jp

急ぎではなかったのですが、素早いご対応ありがとうございます。
丁寧に梱包されていて、手書きのお手紙も入っていました。
配送がゆうパックのみ、というのも個人的には気に入りました。
ルイ ヴィトン 手帳 mm https://www.b2tokei.com/product/detail.aspx?id=8060

タイトル
名前
Url
コメント