001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.wake.remote.impl; 020 021import java.net.SocketAddress; 022 023/** 024 * Event that are exchanged across process boundaries. 025 * 026 * @param <T> type 027 */ 028public class RemoteEvent<T> { 029 030 private final T event; 031 private final long seq; 032 //private static final AtomicLong curSeq = new AtomicLong(0); 033 private SocketAddress localAddr; 034 private SocketAddress remoteAddr; 035 036 /** 037 * Constructs a remote event. 038 * 039 * @param localAddr the local socket address 040 * @param remoteAddr the remote socket address 041 * @param seq the sequence number 042 * @param event the event 043 */ 044 public RemoteEvent(final SocketAddress localAddr, final SocketAddress remoteAddr, final long seq, final T event) { 045 this.localAddr = localAddr; 046 this.remoteAddr = remoteAddr; 047 this.event = event; 048 this.seq = seq; 049 } 050 051 /** 052 * Gets the local socket address. 053 * 054 * @return the local socket address 055 */ 056 public SocketAddress localAddress() { 057 return localAddr; 058 } 059 060 /** 061 * Gets the remote socket address. 062 * 063 * @return the remote socket address 064 */ 065 public SocketAddress remoteAddress() { 066 return remoteAddr; 067 } 068 069 /** 070 * Gets the actual event. 071 * 072 * @return the event 073 */ 074 public T getEvent() { 075 return event; 076 } 077 078 /** 079 * Gets the sequence number. 080 * 081 * @return the sequence number 082 */ 083 public long getSeq() { 084 return seq; 085 } 086 087 /** 088 * Sets the local socket address. 089 * 090 * @param addr the local socket address 091 */ 092 public void setLocalAddress(final SocketAddress addr) { 093 localAddr = addr; 094 } 095 096 /** 097 * Sets the remote socket address. 098 * 099 * @param addr the remote socket address 100 */ 101 public void setRemoteAddress(final SocketAddress addr) { 102 remoteAddr = addr; 103 } 104 105 /** 106 * Returns a string representation of this object. 107 * 108 * @return a string representation of this object 109 */ 110 public String toString() { 111 final StringBuilder builder = new StringBuilder(); 112 builder.append("RemoteEvent"); 113 builder.append(" localAddr="); 114 builder.append(localAddr); 115 builder.append(" remoteAddr="); 116 builder.append(remoteAddr); 117 builder.append(" seq="); 118 builder.append(seq); 119 builder.append(" event="); 120 builder.append(event); 121 return builder.toString(); 122 } 123 124}