⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client-server imaging.htm

📁 是一部关于java高级图像处理的的一本入门书
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0098)http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Client-server.doc.html -->
<HTML><HEAD><TITLE>Client-Server Imaging</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content=exclude name=collection>
<META content="MSHTML 6.00.2900.3132" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<CENTER><A 
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/JAITOC.fm.html"><IMG 
alt=Contents src="Client-Server Imaging.files/contents.gif"></A> <A 
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Properties.doc.html"><IMG 
alt=Previous src="Client-Server Imaging.files/previous.gif"></A> <A 
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Encode.doc.html"><IMG 
alt=Next src="Client-Server Imaging.files/next.gif"></A> 
<P><FONT size=5><I>Programming in Java Advanced Imaging</I></FONT> </CENTER><BR>
<CENTER><A name=47227>
<TABLE width="90%" border=0>
  <TBODY>
  <TR>
    <TD align=right><FONT size=3>C H A P T E R</FONT><FONT size=7><IMG 
      src="Client-Server Imaging.files/sm-space.gif">12</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<CENTER><A name=47285>
<TABLE width="90%" border=0>
  <TBODY>
  <TR>
    <TD align=right>
      <HR noShade SIZE=7>
      <FONT size=6>Client-Server Imaging</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<BLOCKQUOTE>
  <P><BR><BR><BR>
  <P><FONT size=7><B>T</B></FONT>HIS chapter describes JAI's client-server 
  imaging system. 
  <P><A name=51145>
  <H2>12.1 <IMG 
  src="Client-Server Imaging.files/space.gif">Introduction</H2></A>Client-server 
  imaging provides the ability to distribute computation between a set of 
  processing nodes. For example, it is possible to set up a large, powerful 
  server that provides image processing services to several thin clients. With 
  JAI, it is possible for a client to set up a complex imaging chain on a 
  server, including references to source images on other network hosts, and to 
  request rendered output from the server. 
  <P>JAI uses Java Remote Method Invocation (RMI) to implement client-server 
  imaging. To communicate using Remote Method Invocation, both the client and 
  server must be running Java. A <EM>stub</EM> object is instantiated on the 
  client. The stub object forwards its method calls to a corresponding server 
  object. Method call arguments and return values are transmitted between the 
  client and server by means of the Java Development Environment's 
  <EM>serialization</EM> capability. 
  <P>The hostname and port depend on the local setup. The host must be running 
  an RMI registry process and have a <CODE>RemoteImageServer</CODE> listening at 
  the desired port. 
  <P>This call will result in the creation of a server-side 
  <CODE>RMIImageImpl</CODE> object and a client-side stub object. The client 
  stub serializes its method arguments and transfers them to the server over a 
  socket; the server serializes its return values and returns them in the same 
  manner. 
  <P><A name=51212>
  <H2>12.2 <IMG src="Client-Server Imaging.files/space.gif">Server Name and Port 
  Number</H2></A>The <CODE>RemoteImage</CODE> constructor requires a 
  <CODE>serverName</CODE> parameter that consists of a host name and port 
  number, in the following format: 
  <P><PRE>     host:port
</PRE>For example: 
  <P><PRE>     camus.eng.sun.com:1099
</PRE>The port number is optional and need be supplied only if the host name 
  is supplied. If the <CODE>serverName</CODE> parameter is null, the default is 
  to search for the RMIImage service on the local host at the default 
  <EM>rmiregistry</EM> port (1099. 
  <P>
  <TABLE border=0>
    <TBODY>
    <TR>
      <TD><IMG src="Client-Server Imaging.files/cistine.gif"></TD>
      <TD>
        <HR>
        <B>API:</B> <CODE>javax.media.jai.RemoteImage </CODE>
        <HR>
      </TD></TR></TBODY></TABLE><PRE><UL>
<LI>RemoteImage(String serverName, RenderedImage source)
<P></P></LI></UL></PRE>
  <DL><A name=55131>
    <DT>
    <DD>constructs a <CODE>RemoteImage</CODE> from a <CODE>RenderedImage</CODE>.
    <P>
    <TABLE cellPadding=3 border=3>
      <CAPTION><FONT size=-1><B></B></FONT></CAPTION>
      <TBODY>
      <TR vAlign=top>
        <TD rowSpan=2><EM>Parameters</EM>: 
          <P></P>
        <TD><CODE>serverName</CODE> 
          <P></P>
        <TD>The name of the server in the appropriate format. 
          <P></P>
      <TR vAlign=top>
        <TD><CODE>source</CODE> 
          <P></P>
        <TD>A <CODE>RenderedImage</CODE> source. 
          <P></P></TR></TBODY></TABLE></A>
    <P></P></DD></DL><PRE><UL>
<LI>RemoteImage(String serverName, RenderedOp source)
<P></P></LI></UL></PRE>
  <DL><A name=54667>
    <DT>
    <DD>constructs a <CODE>RemoteImage</CODE> from a <CODE>RenderedOp</CODE>, 
    i.e., an imaging DAG (directed acyclic graph). Note that the properties of 
    the <CODE>RemoteImage</CODE> will be those of the <CODE>RenderedOp</CODE> 
    node and not of its rendering. </A>
    <P></P></DD></DL><PRE><UL>
<LI>RemoteImage(String serverName, RenderableOp source, 
RenderContext renderContext)
<P></P></LI></UL></PRE>
  <DL><A name=55160>
    <DT>
    <DD>constructs a <CODE>RemoteImage</CODE> from a <CODE>RenderableOp</CODE> 
    and <CODE>RenderContext</CODE>. The entire <CODE>RenderableOp</CODE> DAG 
    will be copied over to the server. Note that the properties of the 
    <CODE>RemoteImage</CODE> will be those of the <CODE>RenderableOp</CODE> node 
    and not of its rendering. </A>
    <P></P></DD></DL><A name=51218>
  <H2>12.3 <IMG src="Client-Server Imaging.files/space.gif">Setting the Timeout 
  Period and Number of Retries</H2></A>A network error or a delay caused by the 
  server failing to respond to the request for an image is dealt with through 
  retries. If, on the first attempt, the server fails to respond, the program 
  will wait a specified amount of time and then make another request for the 
  image. When the limit of retries is exceeded, a null Raster may be returned. 
  <P>The amount of time to wait between retries defaults to 1 second (1000 
  milliseconds). The <CODE>getTimeout</CODE> method is used to get the amount of 
  time between retries, in milliseconds. The <CODE>setTimeout</CODE> method is 
  used to set the amount of time between retries. 
  <P>The number of times the program will attempt to read the remote image may 
  be read with the <CODE>getNumRetries</CODE> method. The 
  <CODE>setNumRetries</CODE> method is used to set the maximum number of 
  retries. 
  <P>
  <TABLE border=0>
    <TBODY>
    <TR>
      <TD><IMG src="Client-Server Imaging.files/cistine.gif"></TD>
      <TD>
        <HR>
        <B>API:</B> <CODE>javax.media.jai.RemoteImage </CODE>
        <HR>
      </TD></TR></TBODY></TABLE><PRE><UL>
<LI>void setTimeout(int timeout)
<P></P></LI></UL></PRE>
  <DL><A name=54566>
    <DT>
    <DD>sets the amount of time between retries.
    <P>
    <TABLE cellPadding=3 border=3>
      <CAPTION><FONT size=-1><B></B></FONT></CAPTION>
      <TBODY>
      <TR vAlign=top>
        <TD><EM>Parameter</EM>: 
          <P></P>
        <TD><CODE>timeout</CODE> 
          <P></P>
        <TD>The time interval between retries in milliseconds. 
          <P></P></TR></TBODY></TABLE></A>
    <P></P></DD></DL><PRE><UL>
<LI>int getTimeout()
<P></P></LI></UL></PRE>
  <DL><A name=54587>
    <DT>
    <DD>returns the amount of time between retries. </A>
    <P></P></DD></DL><PRE><UL>
<LI>void setNumRetries(int numRetries)
<P></P></LI></UL></PRE>
  <DL><A name=54597>
    <DT>
    <DD>sets the number of retries.
    <P>
    <TABLE cellPadding=3 border=3>
      <CAPTION><FONT size=-1><B></B></FONT></CAPTION>
      <TBODY>
      <TR vAlign=top>
        <TD><EM>Parameter</EM>: 
          <P></P>
        <TD><CODE>numRetries</CODE> 
          <P></P>
        <TD>The maximum number of retries. If this is a negative value, the 
          number of retries is unchanged. 
          <P></P></TR></TBODY></TABLE></A>
    <P></P></DD></DL><A name=51951>
  <H2>12.4 <IMG src="Client-Server Imaging.files/space.gif">Remote Imaging Test 
  Example</H2></A>This section contains two examples of remote imaging programs. 

  <P><A name=51974>
  <H3>12.4.1 <IMG src="Client-Server Imaging.files/space.gif">Simple Remote 
  Imaging Example</H3></A><A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Client-server.doc.html#54012">Listing 
  12-1</A> shows a complete code example of a <CODE>RemoteImaging</CODE> test. 
  This example displays a 2 x 2 grid of <CODE>ScrollingImagePanel</CODE>s, with 
  each window displaying the sum of two byte images that were rescaled to the 
  range [0,127] prior to addition. The panels display the following specific 
  results: 
  <P>
  <UL>
    <LI>upper left: local rendering
    <P></P></LI></UL>
  <UL>
    <LI>upper right: result of remote rendering of a RenderedOp graph
    <P></P></LI></UL>
  <UL>
    <LI>lower left: result of remote loading of a RenderedImage
    <P></P></LI></UL>
  <UL>
    <LI>lower right: result of remote rendering of a RenderableOp graph
    <P></P></LI></UL>The lower right image is a dithered version of the sum image 
  passed through a color cube lookup table and may appear slightly different 
  from the other three images, which should be identical.
  <P><CAPTION><FONT size=-1><B><A name=54012>
  <CENTER><FONT size=-1><B><I>Listing 12-1 </I><IMG 
  src="Client-Server Imaging.files/sm-blank.gif" border=0> Remote Imaging 
  Example Program (Sheet 1 of 4)</B></FONT></CENTER></A>
  <P></B></FONT></CAPTION>
  <HR>
  <TR valign="top"><TD rowspan="10" colspan="1"><PRE>     import java.awt.*;
     import java.awt.event.WindowEvent;
     import java.awt.geom.*;
     import java.awt.image.*;
     import java.awt.image.renderable.*;
     import java.util.*;
     import javax.media.jai.*;
     import javax.media.jai.operator.*;
     import javax.media.jai.widget.*;
     public class RemoteImagingTest extends WindowContainer {
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TD rowspan="2" colspan="1"><PRE>     /** Default remote server. */
     private static final String DEFAULT_SERVER =
                              "camus.eng.sun.com:1099";
</PRE><TR valign="top"><TR valign="top"><TD rowspan="3" colspan="1"><PRE>     /** Tile dimensions. */
     private static final int TILE_WIDTH = 256;
     private static final int TILE_HEIGHT = 256;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="3" 
  colspan="1"><PRE>     public static void main(String args[]) {
     String fileName1 = null;
     String fileName2 = null;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="7" 
  colspan="1"><PRE>     // Check args.
         if(!(args.length &gt;= 0 &amp;&amp; args.length &lt;= 3)) {
            System.out.println("\nUsage: java RemoteImagingTest "+
                           "[[[serverName] | [fileName1 fileName2]] | "+
                           "[serverName fileName1 fileName2]]"+"\n");
            System.exit(1);
         }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TD rowspan="9" colspan="1"><PRE>     // Set the server name.
     String serverName = null;
        if(args.length == 0 || args.length == 2) {
            serverName = DEFAULT_SERVER;
            System.out.println("\nUsing default server '"+
                               DEFAULT_SERVER+"'\n");
        } else {
            serverName = args[0];
        }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TD rowspan="13" colspan="1"><PRE>     // Set the file names.
        if(args.length == 2) {
            fileName1 = args[0];
            fileName2 = args[1];
        } else if(args.length == 3) {
            fileName1 = args[1];
            fileName2 = args[2];
        } else {
      fileName1 = "/import/jai/JAI_RP/test/images/Boat_At_Dock.tif";
      fileName2 = "/import/jai/JAI_RP/test/images/FarmHouse.tif";
            System.out.println("\nUsing default images '"+
                               fileName1 + "' and '" + fileName2 + "'\n");
          }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TD rowspan="3" colspan="1"><PRE>     RemoteImagingTest riTest =
            new RemoteImagingTest(serverName, fileName1, fileName2);
         }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="11" 
  colspan="1"><PRE>     /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -