Fixup checkstyle
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / FrontendIdentifier.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.access.concepts;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.DataInput;
13 import java.io.DataOutput;
14 import java.io.IOException;
15 import java.util.Objects;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.concepts.WritableIdentifier;
18
19 /**
20  * A cluster-wide unique identifier of a frontend type located at a cluster member.
21  */
22 public final class FrontendIdentifier implements WritableIdentifier {
23     @java.io.Serial
24     private static final long serialVersionUID = 1L;
25
26     private final MemberName memberName;
27     private final FrontendType clientType;
28
29     FrontendIdentifier(final MemberName memberName, final FrontendType clientType) {
30         this.clientType = requireNonNull(clientType);
31         this.memberName = requireNonNull(memberName);
32     }
33
34     public static @NonNull FrontendIdentifier create(final MemberName memberName, final FrontendType clientType) {
35         return new FrontendIdentifier(memberName, clientType);
36     }
37
38     public static @NonNull FrontendIdentifier readFrom(final DataInput in) throws IOException {
39         final var memberName = MemberName.readFrom(in);
40         final var clientType = FrontendType.readFrom(in);
41         return new FrontendIdentifier(memberName, clientType);
42     }
43
44     @Override
45     public void writeTo(final DataOutput out) throws IOException {
46         memberName.writeTo(out);
47         clientType.writeTo(out);
48     }
49
50     public @NonNull FrontendType getClientType() {
51         return clientType;
52     }
53
54     public @NonNull MemberName getMemberName() {
55         return memberName;
56     }
57
58     @Override
59     public int hashCode() {
60         return Objects.hash(memberName, clientType);
61     }
62
63     @Override
64     public boolean equals(final Object obj) {
65         return this == obj || obj instanceof FrontendIdentifier other && memberName.equals(other.memberName)
66             && clientType.equals(other.clientType);
67     }
68
69     public @NonNull String toPersistentId() {
70         return memberName.getName() + "-frontend-" + clientType.getName();
71     }
72
73     @Override
74     public String toString() {
75         return toPersistentId();
76     }
77
78     @java.io.Serial
79     private Object writeReplace() {
80         return new FI(this);
81     }
82 }