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 033 //private static final AtomicLong curSeq = new AtomicLong(0); 034 035 private SocketAddress localAddr; 036 private SocketAddress remoteAddr; 037 038 /** 039 * Constructs a remote event. 040 * 041 * @param localAddr the local socket address 042 * @param remoteAddr the remote socket address 043 * @param seq the sequence number 044 * @param event the event 045 */ 046 public RemoteEvent(final SocketAddress localAddr, final SocketAddress remoteAddr, final long seq, final T event) { 047 this.localAddr = localAddr; 048 this.remoteAddr = remoteAddr; 049 this.event = event; 050 this.seq = seq; 051 } 052 053 /** 054 * Gets the local socket address. 055 * 056 * @return the local socket address 057 */ 058 public SocketAddress localAddress() { 059 return localAddr; 060 } 061 062 /** 063 * Gets the remote socket address. 064 * 065 * @return the remote socket address 066 */ 067 public SocketAddress remoteAddress() { 068 return remoteAddr; 069 } 070 071 /** 072 * Gets the actual event. 073 * 074 * @return the event 075 */ 076 public T getEvent() { 077 return event; 078 } 079 080 /** 081 * Gets the sequence number. 082 * 083 * @return the sequence number 084 */ 085 public long getSeq() { 086 return seq; 087 } 088 089 /** 090 * Sets the local socket address. 091 * 092 * @param addr the local socket address 093 */ 094 public void setLocalAddress(final SocketAddress addr) { 095 localAddr = addr; 096 } 097 098 /** 099 * Sets the remote socket address. 100 * 101 * @param addr the remote socket address 102 */ 103 public void setRemoteAddress(final SocketAddress addr) { 104 remoteAddr = addr; 105 } 106 107 /** 108 * Returns a string representation of this object. 109 * 110 * @return a string representation of this object 111 */ 112 public String toString() { 113 return String.format( 114 "RemoteEvent localAddr=%s remoteAddr=%s seq=%d event=%s:%s", 115 this.localAddr, this.remoteAddr, this.seq, this.event.getClass().getCanonicalName(), this.event); 116 } 117}