View Javadoc
1   /**
2    * Copyright (C) 2010-14 pvmanager developers. See COPYRIGHT.TXT
3    * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4    */
5   package org.epics.pvmanager;
6   
7   /**
8    * Groups all the parameters required to add a writer to a ChannelHandler.
9    * <p>
10   * All parameters where grouped in this class so that if something needs to be
11   * added or removed the impact is lessened. The class is immutable so that
12   * the ChannelHandler can cache it for reference.
13   *
14   * @author carcassi
15   */
16  public class ChannelHandlerWriteSubscription {
17  
18      /**
19       * Creates a new subscription.
20       * 
21       * @param writeCache the cache where to read the value from
22       * @param exceptionWriteFunction the write function to notify to process errors
23       * @param connectionWriteFunction the write function to notify for connection updates
24       */
25      public ChannelHandlerWriteSubscription(WriteCache<?> writeCache, WriteFunction<Exception> exceptionWriteFunction, WriteFunction<Boolean> connectionWriteFunction) {
26          this.writeCache = writeCache;
27          this.exceptionWriteFunction = exceptionWriteFunction;
28          this.connectionWriteFunction = connectionWriteFunction;
29      }
30      
31      private final WriteCache<?> writeCache;
32      private final WriteFunction<Exception> exceptionWriteFunction;
33      private final WriteFunction<Boolean> connectionWriteFunction;
34  
35      /**
36       * The cache to hold the value to write.
37       * 
38       * @return the write cache
39       */
40      public WriteCache<?> getWriteCache() {
41          return writeCache;
42      }
43  
44      /**
45       * The write function for connection/disconnection errors.
46       * 
47       * @return the write function; never null
48       */
49      public WriteFunction<Exception> getExceptionWriteFunction() {
50          return exceptionWriteFunction;
51      }
52  
53      /**
54       * The write function for the connection flag.
55       * 
56       * @return the write function; never null
57       */
58      public WriteFunction<Boolean> getConnectionWriteFunction() {
59          return connectionWriteFunction;
60      }
61  
62      @Override
63      public int hashCode() {
64          int hash = 3;
65          hash = 11 * hash + (this.writeCache != null ? this.writeCache.hashCode() : 0);
66          hash = 11 * hash + (this.exceptionWriteFunction != null ? this.exceptionWriteFunction.hashCode() : 0);
67          hash = 11 * hash + (this.connectionWriteFunction != null ? this.connectionWriteFunction.hashCode() : 0);
68          return hash;
69      }
70  
71      @Override
72      public boolean equals(Object obj) {
73          if (obj == null) {
74              return false;
75          }
76          if (getClass() != obj.getClass()) {
77              return false;
78          }
79          final ChannelHandlerWriteSubscription other = (ChannelHandlerWriteSubscription) obj;
80          if (this.writeCache != other.writeCache && (this.writeCache == null || !this.writeCache.equals(other.writeCache))) {
81              return false;
82          }
83          if (this.exceptionWriteFunction != other.exceptionWriteFunction && (this.exceptionWriteFunction == null || !this.exceptionWriteFunction.equals(other.exceptionWriteFunction))) {
84              return false;
85          }
86          if (this.connectionWriteFunction != other.connectionWriteFunction && (this.connectionWriteFunction == null || !this.connectionWriteFunction.equals(other.connectionWriteFunction))) {
87              return false;
88          }
89          return true;
90      }
91      
92  }