blob: da095f1a565b01ff65f545ee14a075d828c73a42 [file] [log] [blame]
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.winegrower.service;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.function.Consumer;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
public class ServiceRegistrationImpl<T> implements ServiceRegistration<T> {
private final String[] classes;
private final Consumer<ServiceRegistration<?>> onUnregister;
private final ServiceReference<T> reference;
private volatile Dictionary<String, ?> properties;
ServiceRegistrationImpl(final String[] classes, final Dictionary<String, ?> properties, final ServiceReferenceImpl<T> reference,
final Consumer<ServiceRegistration<?>> onUnregister) {
this.classes = classes;
this.properties = properties;
this.reference = reference;
this.onUnregister = onUnregister;
reference.setRegistration(this);
}
public String[] getClasses() {
return classes;
}
@Override
public ServiceReference<T> getReference() {
return reference;
}
@Override
public void setProperties(final Dictionary<String, ?> properties) {
this.properties = properties;
}
@Override
public void unregister() {
onUnregister.accept(this);
}
@Override
public String toString() {
return "ServiceRegistrationImpl{classes=" + Arrays.toString(classes) + ", impl=" + reference + "}";
}
}