View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.core.session;
21  
22  import java.io.Serializable;
23  
24  /**
25   * Creates a Key from a class name and an attribute name. The resulting Key will
26   * be stored in the session Map.<br>
27   * For instance, we can create a 'processor' AttributeKey this way :
28   * 
29   * <pre>
30   * private static final AttributeKey PROCESSOR = new AttributeKey(
31   * 	SimpleIoProcessorPool.class, &quot;processor&quot;);
32   * </pre>
33   * 
34   * This will create the <b>SimpleIoProcessorPool.processor@7DE45C99</b> key
35   * which will be stored in the session map.<br>
36   * Such an attributeKey is mainly useful for debug purposes.
37   * 
38   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
39   */
40  public final class AttributeKey implements Serializable {
41      /** The serial version UID */
42      private static final long serialVersionUID = -583377473376683096L;
43      
44      /** The attribute's name */
45      private final String name;
46  
47      /**
48       * Creates a new instance. It's built from :
49       * <ul>
50       * <li>the class' name</li>
51       * <li>the attribute's name</li>
52       * <li>this attribute hashCode</li>
53       * </ul>
54       * 
55       * @param source
56       *            The class this AttributeKey will be attached to
57       * @param name
58       *            The Attribute name
59       */
60      public AttributeKey(Class<?> source, String name) {
61          this.name = source.getName() + '.' + name + '@' + Integer.toHexString(this.hashCode());
62      }
63  
64      /**
65       * The String representation of this object.
66       */
67      @Override
68      public String toString() {
69          return name;
70      }
71  }