001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.replication.protocol; 028 029 import java.io.IOException; 030 import java.net.SocketException; 031 import java.util.zip.DataFormatException; 032 033 /** 034 * The ProtocolSession interface should be implemented by a class that 035 * implement the send/reception part of the Multi-master replication 036 * protocol. 037 * 038 * This interface is designed to make easy the move from one format 039 * of the ReplicationMessage on the wire to another format. 040 */ 041 public interface ProtocolSession 042 { 043 044 /** 045 * This method is called when the session with the remote must be closed. 046 * This object won't be used anymore after this method is called. 047 * 048 * @throws IOException If an error happen during the close process. 049 */ 050 public abstract void close() throws IOException; 051 052 /** 053 * This method is called when a ReplicationMessage must be sent to 054 * the remote entity. 055 * 056 * It can be called by several threads and must implement appropriate 057 * replication (typically, this method or a part of it should be 058 * synchronized). 059 * 060 * @param msg The ReplicationMessage that must be sent. 061 * @throws IOException If an IO error happen during the publish process. 062 */ 063 public abstract void publish(ReplicationMessage msg) 064 throws IOException; 065 066 /** 067 * Attempt to receive a ReplicationMessage. 068 * This method should block the calling thread until a 069 * ReplicationMessage is available or until an error condition. 070 * 071 * This method can only be called by a single thread and therefore does not 072 * neet to implement any replication. 073 * 074 * @return The ReplicationMessage that was received. 075 * @throws IOException When error happened durin IO process. 076 * @throws ClassNotFoundException When the data received does extend the 077 * ReplicationMessage class. 078 * @throws DataFormatException When the data received is not formatted as a 079 * ReplicationMessage. 080 */ 081 public abstract ReplicationMessage receive() 082 throws IOException, ClassNotFoundException, 083 DataFormatException; 084 085 /** 086 * Stop using the security layer, if there is any. 087 */ 088 public abstract void stopEncryption(); 089 090 /** 091 * Determine whether the session is using a security layer. 092 * @return true if the connection is encrypted, false otherwise. 093 */ 094 public abstract boolean isEncrypted(); 095 096 /** 097 * Retrieve the IP address of the remote server. 098 * 099 * @return The IP address of the remote server. 100 */ 101 public abstract String getRemoteAddress(); 102 103 104 /** 105 * Set a timeout value. 106 * With this option set to a non-zero value, calls to the receive() method 107 * block for only this amount of time after which a 108 * java.net.SocketTimeoutException is raised. 109 * The Broker is valid and useable even after such an Exception is raised. 110 * 111 * @param timeout the specified timeout, in milliseconds. 112 * @throws SocketException if there is an error in the underlying protocol, 113 * such as a TCP error. 114 */ 115 public abstract void setSoTimeout(int timeout) throws SocketException; 116 117 118 119 /** 120 * Gets the time the last replication message was published on this 121 * session. 122 * @return The timestamp in milliseconds of the last message published. 123 */ 124 public abstract long getLastPublishTime(); 125 126 127 128 /** 129 * Gets the time the last replication message was received on this 130 * session. 131 * @return The timestamp in milliseconds of the last message received. 132 */ 133 public abstract long getLastReceiveTime(); 134 }