View Javadoc
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.dns;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.ByteBufHolder;
20  
21  /**
22   * Represents any resource record (answer, authority, or additional resource
23   * records).
24   */
25  public final class DnsResource extends DnsEntry implements ByteBufHolder {
26  
27      private final long ttl;
28      private final ByteBuf content;
29  
30      /**
31       * Constructs a resource record.
32       *
33       * @param name
34       *            the domain name
35       * @param type
36       *            the type of record being returned
37       * @param aClass
38       *            the class for this resource record
39       * @param ttl
40       *            the time to live after reading
41       * @param content
42       *            the data contained in this record
43       */
44      public DnsResource(String name, DnsType type, DnsClass aClass, long ttl, ByteBuf content) {
45          super(name, type, aClass);
46          this.ttl = ttl;
47          this.content = content;
48      }
49  
50      /**
51       * Returns the time to live after reading for this resource record.
52       */
53      public long timeToLive() {
54          return ttl;
55      }
56  
57      /**
58       * Returns the data contained in this resource record.
59       */
60      @Override
61      public ByteBuf content() {
62          return content;
63      }
64  
65      /**
66       * Returns a deep copy of this resource record.
67       */
68      @Override
69      public DnsResource copy() {
70          return new DnsResource(name(), type(), dnsClass(), ttl, content.copy());
71      }
72  
73      /**
74       * Returns a duplicate of this resource record.
75       */
76      @Override
77      public DnsResource duplicate() {
78          return new DnsResource(name(), type(), dnsClass(), ttl, content.duplicate());
79      }
80  
81      @Override
82      public int refCnt() {
83          return content.refCnt();
84      }
85  
86      @Override
87      public DnsResource retain() {
88          content.retain();
89          return this;
90      }
91  
92      @Override
93      public DnsResource retain(int increment) {
94          content.retain(increment);
95          return this;
96      }
97  
98      @Override
99      public boolean release() {
100         return content.release();
101     }
102 
103     @Override
104     public boolean release(int decrement) {
105         return content.release(decrement);
106     }
107 
108     @Override
109     public DnsResource touch() {
110         content.touch();
111         return this;
112     }
113 
114     @Override
115     public DnsResource touch(Object hint) {
116         content.touch(hint);
117         return this;
118     }
119 }