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

📄 client.java

📁 这是一个分布式通信程序框架源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,    long data);
    /**
     * Sends a float data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,   float data);
    /**
     * Sends a double data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,  double data);
    /**
     * Sends a String data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,  String data);

    /**
     * Sends a boolean array data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved, boolean[] dataArray);
    /**
     * Sends a char data array item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,    char[] dataArray);
    /**
     * Sends a byte array data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,    byte[] dataArray);
    /**
     * Sends a short array data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,   short[] dataArray);
    /**
     * Sends a int array data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,     int[] dataArray);
    /**
     * Sends a long array data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,    long[] dataArray);
    /**
     * Sends a float array data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,   float[] dataArray);
    /**
     * Sends a double array data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,  double[] dataArray);

    /**
     * Sends a nativeDataBlock data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    private static native int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,  long nativeDataBlock, int nativeDataSize);

    /**
     * Sends a nativeDataBlock data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,  Memory theData)
    {
        return send(name, aCompletionHandler, mode, reserved, theData.dataAddress, theData.highWaterMark);
    }
    /**
     * Sends a nativeDataBlock data item to the named service.
     * @see #send(java.lang.String, CompletionHandler, int, int, boolean)
     */
    public static int send(String name, CompletionHandler aCompletionHandler, int mode, int reserved,  DataEncoder aNativeDataEncoder)
    {
        Memory theData = aNativeDataEncoder.encodeData();
        return send(name, aCompletionHandler, mode, reserved, theData.dataAddress, theData.highWaterMark);
    }


    /**
     * Subscribe to a named service.
     * @param name The name of the named service.
     * @param data An object that implements the <code>DataDecoder</code> interface that will receive the data.
     * @param mode A parameter to control to mode of the send operation.
     * <BR> The following options are recognized:
     * <UL>
     * <LI> {@link #ONCE_ONLY} Make a once only subscription.
     * The timeout parameter specifies the time interval by which the reply should arrive.
     * <LI> {@link #TIMED} Make a timed subscription.
     * The timeout parameter specifies the time interval by which the data will be refreshed.
     * <LI> {@link #MONITORED} Make a monitored subscription.
     * The data will be refreshed when signalled by the server.
     * If a non zero timeout value is given, the data will also be refreshed periodically.
     * </LI></UL>
     * In addition, the following modification flags can be added to the mode:
     * <UL>
     * <LI> {@link #F_STAMPED} Make the data reception time stamped.
     * <LI> {@link #F_WAIT} Wait for receive delivery completion.
     * In case the wait option is used with any subscription mode (i.e. {@link #TIMED} or {@link #MONITORED}), the method will block until the
     * first data delivery.
     * </LI></UL>
     * @param timeout Defines the timeout or the refresh rate of the data.
     * @return The service identification of the subscription. The service identification is required to
     * unsubscribe from the service.
     * <p> <b>Remark:</b><br> The responsability to release a service which is not {@link #ONCE_ONLY} is with the client.
     * To unsubscribe to a service the client should use the service_id which is returned by this method.
     *
     */
    public static native int infoService(String name, DataDecoder data, int mode, int timeout);
    /**
     * Releases a subscribtion to a service.
     * @param serviceId The service id that was returned when the subscribtion was made.
     */
    public static native void releaseService(int serviceId);
    /**
     * No Padding on received structures
     */
    public static native void noPadding();

	public static native String getFormat(int serviceId);
    /**
     * Inform the Server that this client would like the Server to execute an ExitHandler when it dies.
     */
    public static int setExitHandler ( String serverName)
    {
        return send(serverName + "/EXIT", null, 0, 0, (int) 1);
    }

	/**
	 * get the name of the server providing the current service;
	 * This method can be invoked during the execution of the encodeData or decodeData methods.
	 * Outside the scope of these methods, the return will be meaningless.
	 * @return The name of the current server.
	 */
	public static native String getServer();

	/**
	 * get the list of services subscribed by the current server;
	 * This method can be invoked during the execution of the encodeData or decodeData methods.
	 * or during the error_handling method.
	 * Outside the scope of these methods, the return will be meaningless.
	 * @return The list of services separated by '\n'.
	 */
	public static native String getServices();
	
	public static native void stop();
	/**
	 * get the internal connection number of the current server;
	 * This method can be invoked during the execution of the encodeData or decodeData methods.
	 * Outside the scope of these methods, the return will be meaningless.
	 * @return The internal connection number of the client, an index in the range from 0 to the maximum
	 * number of subscribing clients to the server.
	 */
	public static native int    getServerConnID();

    /**  @todo look at these not implemented client functions
     *   public static void change_address(int service_id, int new_address, int new_size);
     *   public static native int find_service(string name);		// not implemented ?
     *   public static native string get_id();				// name@node of client ??
     *   public static native int get_quality(int service_id);
     *   public static native int get_timestamp(int service_id, int *secs, int *milisecs);
     *   public static native string get_format(int service_id);
     *   public static native void disable_padding();			// not implemented ?
     */

    /**
     * A simple class that provides an Object Oriented interface wrapper around the infoService function.
     * <p>
     * This class may in a future release be extended with convenience methods to inquire on subscription
     * properties such as name, name and network address of the implementing server, availability, format etc.
     * <p>
     * In a future version this class will be extended with an autmatic call to release service once there
     * are no more references to this class. To ensure continuation of the subscription, the user should keep
     * a reference to this class as long as its services are required.
     * <br>For performance and stability reasons, however, the user is encouraged to use the release method
     * explicitly and not to rely on the automatic clean up facility (which is not actually implemented).
     * @see #infoService
     * @todo implement a getStatus method
     */
    public static class Subscription
    {
        /**
         * The service_id off the server.
         */
        private int serviceId;

        /**
         * Creates a new instance of a subscription.
         * @see #infoService
         */
        public Subscription(String name, DataDecoder data, int mode, int timeout)
        {
            serviceId = infoService(name, data, mode, timeout);
        }

        /**
         * Releases the subscribtion.
         */
        public void release()
        {
            releaseService(serviceId);
        }
    }
}

⌨️ 快捷键说明

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