This project has retired. For details please refer to its Attic page.
Source code
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  private String src;
036  private String sink;
037
038  /**
039   * Constructs a remote event
040   *
041   * @param localAddr  the local socket address
042   * @param remoteAddr the remote socket address
043   * @param src        the source
044   * @param sink       the remote sink
045   * @param seq        the sequence number
046   * @param event      the event
047   */
048  public RemoteEvent(SocketAddress localAddr, SocketAddress remoteAddr, String src, String sink, long seq, T event) {
049    this.localAddr = localAddr;
050    this.remoteAddr = remoteAddr;
051    this.src = src;
052    this.sink = sink;
053    this.event = event;
054    this.seq = seq;
055  }
056
057  /**
058   * Gets the local socket address
059   *
060   * @return the local socket address
061   */
062  public SocketAddress localAddress() {
063    return localAddr;
064  }
065
066  /**
067   * Gets the remote socket address
068   *
069   * @return the remote socket address
070   */
071  public SocketAddress remoteAddress() {
072    return remoteAddr;
073  }
074
075  /**
076   * Gets the source
077   *
078   * @return the source
079   */
080  public String getSource() {
081    return src;
082  }
083
084  /**
085   * Sets the source
086   *
087   * @param name the source name
088   */
089  public void setSource(String name) {
090    src = name;
091  }
092
093  /**
094   * Gets the sink
095   *
096   * @return the sink
097   */
098  public String getSink() {
099    return sink;
100  }
101
102  /**
103   * Sets the sink
104   *
105   * @param name the sink name
106   */
107  public void setSink(String name) {
108    sink = name;
109  }
110
111  /**
112   * Gets the actual event
113   *
114   * @return the event
115   */
116  public T getEvent() {
117    return event;
118  }
119
120  /**
121   * Gets the sequence number
122   *
123   * @return the sequence number
124   */
125  public long getSeq() {
126    return seq;
127  }
128
129  /**
130   * Sets the local socket address
131   *
132   * @param addr the local socket address
133   */
134  public void setLocalAddress(SocketAddress addr) {
135    localAddr = addr;
136  }
137
138  /**
139   * Sets the remote socket address
140   *
141   * @param addr the remote socket address
142   */
143  public void setRemoteAddress(SocketAddress addr) {
144    remoteAddr = addr;
145  }
146
147  /**
148   * Returns a string representation of this object
149   *
150   * @return a string representation of this object
151   */
152  public String toString() {
153    StringBuilder builder = new StringBuilder();
154    builder.append("RemoteEvent");
155    builder.append(" localAddr=");
156    builder.append(localAddr);
157    builder.append(" remoteAddr=");
158    builder.append(remoteAddr);
159    builder.append(" sourceName=");
160    builder.append(src);
161    builder.append(" sinkName=");
162    builder.append(sink);
163    builder.append(" seq=");
164    builder.append(seq);
165    builder.append(" event=");
166    builder.append(event);
167    return builder.toString();
168  }
169
170}