2 * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved.
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
8 package org.opendaylight.lispflowmapping.implementation.lisp;
10 import java.util.HashSet;
12 import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil;
13 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
14 import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
15 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceSubscriberRLOC;
16 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer;
18 public abstract class AbstractLispComponent {
20 public static final String PASSWORD_SUBKEY = "password";
21 public static final String ADDRESS_SUBKEY = "address";
22 public static final String SUBSCRIBERS_SUBKEY = "subscribers";
24 protected ILispDAO dao;
25 protected volatile boolean iterateMask;
26 protected volatile boolean authenticate;
28 public AbstractLispComponent(ILispDAO dao, boolean authenticate, boolean iterateMask) {
30 this.iterateMask = iterateMask;
31 this.authenticate = authenticate;
34 public boolean shouldIterateMask() {
38 public void setShouldIterateMask(boolean shouldIterateMask) {
39 this.iterateMask = shouldIterateMask;
42 public boolean shouldAuthenticate() {
46 public void setShouldAuthenticate(boolean shouldAuthenticate) {
47 this.authenticate = shouldAuthenticate;
50 protected String getPassword(LispAddressContainer prefix, int maskLength) {
51 while (maskLength >= 0) {
52 IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(prefix, maskLength);
53 Object password = dao.getSpecific(key, PASSWORD_SUBKEY);
54 if (password != null && password instanceof String) {
55 return (String) password;
56 } else if (shouldIterateMask()) {
65 @SuppressWarnings("unchecked")
66 protected HashSet<MappingServiceSubscriberRLOC> getSubscribers(LispAddressContainer prefix, int maskLength) {
67 IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(prefix, maskLength);
68 Object subscribers = dao.getSpecific(key, SUBSCRIBERS_SUBKEY);
69 if (subscribers != null && subscribers instanceof HashSet<?>) {
70 return (HashSet<MappingServiceSubscriberRLOC>) subscribers;