repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
null |
wildfly-main/clustering/service/src/main/java/org/wildfly/clustering/service/SimpleServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.service;
import java.util.function.Consumer;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
/**
* Configures a simple {@link Service} that provides a static value.
* @author Paul Ferraro
*/
public class SimpleServiceConfigurator<T> extends SimpleServiceNameProvider implements ServiceConfigurator {
private final T value;
public SimpleServiceConfigurator(ServiceName name, T value) {
super(name);
this.value = value;
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<T> injector = builder.provides(this.getServiceName());
return builder.setInstance(Service.newInstance(injector, this.value));
}
}
| 1,935
| 36.230769
| 108
|
java
|
null |
wildfly-main/clustering/service/src/main/java/org/wildfly/clustering/service/DefaultableUnaryRequirement.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.service;
/**
* Identifies a requirement that provides a service and can reference some default requirement.
* @author Paul Ferraro
*/
public interface DefaultableUnaryRequirement extends UnaryRequirement {
Requirement getDefaultRequirement();
@Override
default Class<?> getType() {
return this.getDefaultRequirement().getType();
}
@Override
default String resolve(String name) {
return (name != null) ? UnaryRequirement.super.resolve(name) : this.getDefaultRequirement().getName();
}
}
| 1,591
| 36.904762
| 110
|
java
|
null |
wildfly-main/clustering/service/src/main/java/org/wildfly/clustering/service/CompositeDependency.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.service;
import org.jboss.msc.service.ServiceBuilder;
/**
* @author Paul Ferraro
*/
public class CompositeDependency implements Dependency {
private final Dependency[] dependencies;
public CompositeDependency(Dependency... dependencies) {
this.dependencies = dependencies;
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
for (Dependency dependency : this.dependencies) {
if (dependency != null) {
dependency.register(builder);
}
}
return builder;
}
}
| 1,640
| 33.1875
| 70
|
java
|
null |
wildfly-main/clustering/service/src/main/java/org/wildfly/clustering/service/concurrent/ServiceExecutor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.service.concurrent;
import java.util.Optional;
import java.util.function.Supplier;
import org.wildfly.common.function.ExceptionSupplier;
/**
* Allows safe invocation of tasks that require resources not available after {@link #close(Runnable)} to block a service from stopping.
* @author Paul Ferraro
* @deprecated To be removed without replacement
*/
@Deprecated(forRemoval = true)
public interface ServiceExecutor extends Executor {
/**
* Executes the specified task, but only if the service was not already closed.
* If service is already closed, the task is not run.
* If executed, the specified task must return a non-null value, to be distinguishable from a non-execution.
* @param executeTask a task to execute
* @return an optional value that is present only if the specified task was run.
*/
<R> Optional<R> execute(Supplier<R> executeTask);
/**
* Executes the specified task, but only if the service was not already closed.
* If service is already closed, the task is not run.
* If executed, the specified task must return a non-null value, to be distinguishable from a non-execution.
* @param executeTask a task to execute
* @return an optional value that is present only if the specified task was run.
* @throws E if the task execution failed
*/
<R, E extends Exception> Optional<R> execute(ExceptionSupplier<R, E> executeTask) throws E;
/**
* Closes the service, executing the specified task, first waiting for any concurrent executions to complete.
* The specified task will only execute once, irrespective on subsequent {@link #close(Runnable)} invocations.
* @param closeTask a task which closes the service
*/
void close(Runnable closeTask);
}
| 2,834
| 43.296875
| 136
|
java
|
null |
wildfly-main/clustering/service/src/main/java/org/wildfly/clustering/service/concurrent/Executor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.service.concurrent;
import org.wildfly.common.function.ExceptionRunnable;
/**
* Extends {@link java.util.concurrent.Executor} to additionally support a {@link ExceptonRunnable}.
* @author Paul Ferraro
* @deprecated To be removed without replacement
*/
@Deprecated(forRemoval = true)
public interface Executor extends java.util.concurrent.Executor {
/**
* Executes the specified runner.
* @param <E> the exception type
* @param runner a runnable task
* @throws E if execution fails
*/
<E extends Exception> void execute(ExceptionRunnable<E> runner) throws E;
}
| 1,655
| 37.511628
| 100
|
java
|
null |
wildfly-main/clustering/service/src/main/java/org/wildfly/clustering/service/concurrent/StampedLockServiceExecutor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.service.concurrent;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Supplier;
import org.wildfly.common.function.ExceptionRunnable;
import org.wildfly.common.function.ExceptionSupplier;
/**
* {@link ServiceExecutor} implemented via a {@link StampedLock}.
* @author Paul Ferraro
* @deprecated To be removed without replacement
*/
@Deprecated(forRemoval = true)
public class StampedLockServiceExecutor implements ServiceExecutor {
private final StampedLock lock = new StampedLock();
private final AtomicBoolean closed = new AtomicBoolean(false);
@Override
public void execute(Runnable executeTask) {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
executeTask.run();
} finally {
this.lock.unlock(stamp);
}
}
}
@Override
public <E extends Exception> void execute(ExceptionRunnable<E> executeTask) throws E {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
executeTask.run();
} finally {
this.lock.unlock(stamp);
}
}
}
@Override
public <R> Optional<R> execute(Supplier<R> executeTask) {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
return Optional.of(executeTask.get());
} finally {
this.lock.unlock(stamp);
}
}
return Optional.empty();
}
@Override
public <R, E extends Exception> Optional<R> execute(ExceptionSupplier<R, E> executeTask) throws E {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
return Optional.of(executeTask.get());
} finally {
this.lock.unlock(stamp);
}
}
return Optional.empty();
}
@Override
public void close(Runnable closeTask) {
// Allow only one thread to close
if (this.closed.compareAndSet(false, true)) {
// Closing is final - we don't need the stamp
this.lock.writeLock();
closeTask.run();
}
}
}
| 3,367
| 31.384615
| 103
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/test/java/org/jboss/as/clustering/jgroups/ManagedSocketFactoryTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.Closeable;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;
import java.util.List;
import java.util.Map;
import org.jboss.as.network.ManagedServerSocketFactory;
import org.jboss.as.network.ManagedSocketFactory;
import org.jboss.as.network.SocketBinding;
import org.jboss.as.network.SocketBindingManager;
import org.jboss.as.network.SocketBindingManager.NamedManagedBindingRegistry;
import org.jboss.as.network.SocketBindingManager.UnnamedBindingRegistry;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
/**
* @author Paul Ferraro
*/
public class ManagedSocketFactoryTestCase {
private final SocketBindingManager manager = mock(SocketBindingManager.class);
private final SelectorProvider provider = mock(SelectorProvider.class);
private final SocketFactory subject = new org.jboss.as.clustering.jgroups.ManagedSocketFactory(this.provider, this.manager, Map.of("known-service", new SocketBinding("binding", 0, false, null, 0, null, this.manager, List.of())));
@Test
public void createSocket() throws IOException {
this.createSocket("known-service", "binding");
this.createSocket("unknown-service", null);
}
private void createSocket(String serviceName, String bindingName) throws IOException {
ManagedSocketFactory factory = mock(ManagedSocketFactory.class);
Socket socket = mock(Socket.class);
when(this.manager.getSocketFactory()).thenReturn(factory);
if (bindingName != null) {
when(factory.createSocket(bindingName)).thenReturn(socket);
} else {
when(factory.createSocket()).thenReturn(socket);
}
try (Socket result = this.subject.createSocket(serviceName)) {
assertSame(socket, result);
verify(socket, never()).bind(any());
verify(socket, never()).connect(any());
}
reset(socket);
InetAddress connectAddress = InetAddress.getLocalHost();
int connectPort = 1;
try (Socket result = this.subject.createSocket(serviceName, connectAddress, connectPort)) {
assertSame(socket, result);
verify(socket, never()).bind(any());
ArgumentCaptor<InetSocketAddress> capturedConnectAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).connect(capturedConnectAddress.capture());
InetSocketAddress connectSocketAddress = capturedConnectAddress.getValue();
assertEquals(connectAddress, connectSocketAddress.getAddress());
assertEquals(connectPort, connectSocketAddress.getPort());
}
reset(socket);
try (Socket result = this.subject.createSocket(serviceName, connectAddress.getHostName(), connectPort)) {
assertSame(socket, result);
verify(socket, never()).bind(any());
ArgumentCaptor<InetSocketAddress> capturedConnectAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).connect(capturedConnectAddress.capture());
InetSocketAddress connectSocketAddress = capturedConnectAddress.getValue();
assertEquals(connectAddress, connectSocketAddress.getAddress());
assertEquals(connectPort, connectSocketAddress.getPort());
}
reset(socket);
InetAddress bindAddress = InetAddress.getLoopbackAddress();
int bindPort = 2;
try (Socket result = this.subject.createSocket(serviceName, connectAddress, connectPort, bindAddress, bindPort)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedBindAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).bind(capturedBindAddress.capture());
InetSocketAddress bindSocketAddress = capturedBindAddress.getValue();
assertEquals(bindAddress, bindSocketAddress.getAddress());
assertEquals(bindPort, bindSocketAddress.getPort());
ArgumentCaptor<InetSocketAddress> capturedConnectAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).connect(capturedConnectAddress.capture());
InetSocketAddress connectSocketAddress = capturedConnectAddress.getValue();
assertEquals(connectAddress, connectSocketAddress.getAddress());
assertEquals(connectPort, connectSocketAddress.getPort());
}
reset(socket);
try (Socket result = this.subject.createSocket(serviceName, connectAddress.getHostName(), connectPort, bindAddress, bindPort)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedBindAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).bind(capturedBindAddress.capture());
InetSocketAddress bindSocketAddress = capturedBindAddress.getValue();
assertEquals(bindAddress, bindSocketAddress.getAddress());
assertEquals(bindPort, bindSocketAddress.getPort());
ArgumentCaptor<InetSocketAddress> capturedConnectAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).connect(capturedConnectAddress.capture());
InetSocketAddress connectSocketAddress = capturedConnectAddress.getValue();
assertEquals(connectAddress, connectSocketAddress.getAddress());
assertEquals(connectPort, connectSocketAddress.getPort());
}
}
@Test
public void createServerSocket() throws IOException {
this.createServerSocket("known-service", "binding");
this.createServerSocket("unknown-service", null);
}
private void createServerSocket(String serviceName, String bindingName) throws IOException {
ManagedServerSocketFactory factory = mock(ManagedServerSocketFactory.class);
ServerSocket socket = mock(ServerSocket.class);
when(this.manager.getServerSocketFactory()).thenReturn(factory);
if (bindingName != null) {
when(factory.createServerSocket(bindingName)).thenReturn(socket);
} else {
when(factory.createServerSocket()).thenReturn(socket);
}
try (ServerSocket result = this.subject.createServerSocket(serviceName)) {
assertSame(socket, result);
verify(socket, never()).bind(any());
}
reset(socket);
int bindPort = 1;
try (ServerSocket result = this.subject.createServerSocket(serviceName, bindPort)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).bind(capturedAddress.capture(), eq(SocketFactory.DEFAULT_BACKLOG));
InetSocketAddress address = capturedAddress.getValue();
assertTrue(address.getAddress().isAnyLocalAddress());
assertEquals(bindPort, address.getPort());
}
reset(socket);
int backlog = 10;
try (ServerSocket result = this.subject.createServerSocket(serviceName, bindPort, backlog)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).bind(capturedAddress.capture(), eq(backlog));
InetSocketAddress address = capturedAddress.getValue();
assertTrue(address.getAddress().isAnyLocalAddress());
assertEquals(bindPort, address.getPort());
}
reset(socket);
InetAddress bindAddress = InetAddress.getLoopbackAddress();
try (ServerSocket result = this.subject.createServerSocket(serviceName, bindPort, backlog, bindAddress)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
verify(socket).bind(capturedAddress.capture(), eq(backlog));
InetSocketAddress address = capturedAddress.getValue();
assertEquals(bindAddress, address.getAddress());
assertEquals(bindPort, address.getPort());
}
reset(socket);
}
@Test
public void createDatagramSocket() throws IOException {
this.createDatagramSocket("known-service", "binding");
this.createDatagramSocket("unknown-service", null);
}
private void createDatagramSocket(String serviceName, String bindingName) throws IOException {
DatagramSocket socket = mock(DatagramSocket.class);
if (bindingName != null) {
when(this.manager.createDatagramSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createDatagramSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (DatagramSocket result = this.subject.createDatagramSocket(serviceName)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
if (bindingName != null) {
verify(this.manager).createDatagramSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createDatagramSocket(capturedAddress.capture());
}
InetSocketAddress address = capturedAddress.getValue();
assertTrue(address.getAddress().isAnyLocalAddress());
assertEquals(0, address.getPort());
}
reset(socket, this.manager);
int bindPort = 1;
if (bindingName != null) {
when(this.manager.createDatagramSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createDatagramSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (DatagramSocket result = this.subject.createDatagramSocket(serviceName, bindPort)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
if (bindingName != null) {
verify(this.manager).createDatagramSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createDatagramSocket(capturedAddress.capture());
}
InetSocketAddress address = capturedAddress.getValue();
assertTrue(address.getAddress().isAnyLocalAddress());
assertEquals(bindPort, address.getPort());
}
reset(socket, this.manager);
InetAddress bindAddress = InetAddress.getLocalHost();
if (bindingName != null) {
when(this.manager.createDatagramSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createDatagramSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (DatagramSocket result = this.subject.createDatagramSocket(serviceName, bindPort, bindAddress)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
if (bindingName != null) {
verify(this.manager).createDatagramSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createDatagramSocket(capturedAddress.capture());
}
InetSocketAddress address = capturedAddress.getValue();
assertSame(bindAddress, address.getAddress());
assertEquals(bindPort, address.getPort());
}
reset(socket, this.manager);
if (bindingName != null) {
when(this.manager.createDatagramSocket(eq(bindingName))).thenReturn(socket);
} else {
when(this.manager.createDatagramSocket()).thenReturn(socket);
}
try (DatagramSocket result = this.subject.createDatagramSocket(serviceName, null)) {
assertSame(socket, result);
}
reset(socket, this.manager);
SocketAddress socketAddress = new InetSocketAddress(bindAddress, bindPort);
if (bindingName != null) {
when(this.manager.createDatagramSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createDatagramSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (DatagramSocket result = this.subject.createDatagramSocket(serviceName, socketAddress)) {
assertSame(socket, result);
ArgumentCaptor<SocketAddress> capturedAddress = ArgumentCaptor.forClass(SocketAddress.class);
if (bindingName != null) {
verify(this.manager).createDatagramSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createDatagramSocket(capturedAddress.capture());
}
assertSame(socketAddress, capturedAddress.getValue());
}
}
@Test
public void createMulticastSocket() throws IOException {
this.createMulticastSocket("known-service", "binding");
this.createMulticastSocket("unknown-service", null);
}
private void createMulticastSocket(String serviceName, String bindingName) throws IOException {
MulticastSocket socket = mock(MulticastSocket.class);
if (bindingName != null) {
when(this.manager.createMulticastSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createMulticastSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (MulticastSocket result = this.subject.createMulticastSocket(serviceName)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
if (bindingName != null) {
verify(this.manager).createMulticastSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createMulticastSocket(capturedAddress.capture());
}
InetSocketAddress address = capturedAddress.getValue();
assertTrue(address.getAddress().isAnyLocalAddress());
assertEquals(0, address.getPort());
}
reset(socket, this.manager);
int bindPort = 1;
if (bindingName != null) {
when(this.manager.createMulticastSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createMulticastSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (MulticastSocket result = this.subject.createMulticastSocket(serviceName, bindPort)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
if (bindingName != null) {
verify(this.manager).createMulticastSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createMulticastSocket(capturedAddress.capture());
}
InetSocketAddress address = capturedAddress.getValue();
assertTrue(address.getAddress().isAnyLocalAddress());
assertEquals(bindPort, address.getPort());
}
reset(socket, this.manager);
InetAddress bindAddress = InetAddress.getLocalHost();
if (bindingName != null) {
when(this.manager.createMulticastSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createMulticastSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (MulticastSocket result = this.subject.createMulticastSocket(serviceName, bindPort, bindAddress)) {
assertSame(socket, result);
ArgumentCaptor<InetSocketAddress> capturedAddress = ArgumentCaptor.forClass(InetSocketAddress.class);
if (bindingName != null) {
verify(this.manager).createMulticastSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createMulticastSocket(capturedAddress.capture());
}
InetSocketAddress address = capturedAddress.getValue();
assertSame(bindAddress, address.getAddress());
assertEquals(bindPort, address.getPort());
}
reset(socket, this.manager);
if (bindingName != null) {
when(this.manager.createMulticastSocket(eq(bindingName))).thenReturn(socket);
} else {
when(this.manager.createMulticastSocket()).thenReturn(socket);
}
try (MulticastSocket result = this.subject.createMulticastSocket(serviceName, null)) {
assertSame(socket, result);
}
reset(socket, this.manager);
SocketAddress socketAddress = new InetSocketAddress(bindAddress, bindPort);
if (bindingName != null) {
when(this.manager.createMulticastSocket(eq(bindingName), any())).thenReturn(socket);
} else {
when(this.manager.createMulticastSocket(ArgumentMatchers.<SocketAddress>any())).thenReturn(socket);
}
try (MulticastSocket result = this.subject.createMulticastSocket(serviceName, socketAddress)) {
assertSame(socket, result);
ArgumentCaptor<SocketAddress> capturedAddress = ArgumentCaptor.forClass(SocketAddress.class);
if (bindingName != null) {
verify(this.manager).createMulticastSocket(eq(bindingName), capturedAddress.capture());
} else {
verify(this.manager).createMulticastSocket(capturedAddress.capture());
}
assertSame(socketAddress, capturedAddress.getValue());
}
}
@Test
public void createSocketChannel() throws IOException {
this.createSocketChannel("known-service", "binding");
this.createSocketChannel("unknown-service", null);
}
private void createSocketChannel(String serviceName, String bindingName) throws IOException {
NamedManagedBindingRegistry namedRegistry = mock(NamedManagedBindingRegistry.class);
UnnamedBindingRegistry unnamedRegistry = mock(UnnamedBindingRegistry.class);
when(this.manager.getNamedRegistry()).thenReturn(namedRegistry);
when(this.manager.getUnnamedRegistry()).thenReturn(unnamedRegistry);
Closeable namedRegistration = mock(Closeable.class);
Closeable unnamedRegistration = mock(Closeable.class);
// Validate registration after connect
try (SocketChannel channel = SocketChannel.open()) {
when(this.provider.openSocketChannel()).thenReturn(channel);
when(namedRegistry.registerChannel(eq(bindingName), same(channel))).thenReturn(namedRegistration);
when(unnamedRegistry.registerChannel(same(channel))).thenReturn(unnamedRegistration);
SocketChannel result = this.subject.createSocketChannel(serviceName);
assertSame(channel, result);
// If registration was successful, close of channel should trigger registration close
this.subject.close(result);
verify((bindingName != null) ? namedRegistration : unnamedRegistration).close();
verify((bindingName == null) ? namedRegistration : unnamedRegistration, never()).close();
}
}
@Test
public void createServerSocketChannel() throws IOException {
this.createServerSocketChannel("known-service", "binding");
this.createServerSocketChannel("unknown-service", null);
}
private void createServerSocketChannel(String serviceName, String bindingName) throws IOException {
NamedManagedBindingRegistry namedRegistry = mock(NamedManagedBindingRegistry.class);
UnnamedBindingRegistry unnamedRegistry = mock(UnnamedBindingRegistry.class);
when(this.manager.getNamedRegistry()).thenReturn(namedRegistry);
when(this.manager.getUnnamedRegistry()).thenReturn(unnamedRegistry);
Closeable namedRegistration = mock(Closeable.class);
Closeable unnamedRegistration = mock(Closeable.class);
// Validate registration after bind
try (ServerSocketChannel channel = ServerSocketChannel.open()) {
when(this.provider.openServerSocketChannel()).thenReturn(channel);
when(namedRegistry.registerChannel(eq(bindingName), same(channel))).thenReturn(namedRegistration);
when(unnamedRegistry.registerChannel(same(channel))).thenReturn(unnamedRegistration);
ServerSocketChannel result = this.subject.createServerSocketChannel(serviceName);
assertSame(channel, result);
// If registration was successful, close of channel should trigger registration close
this.subject.close(result);
verify((bindingName != null) ? namedRegistration : unnamedRegistration).close();
verify((bindingName == null) ? namedRegistration : unnamedRegistration, never()).close();
}
}
@Test
public void closeSocket() throws IOException {
Socket socket = mock(Socket.class);
this.subject.close(socket);
verify(socket).close();
}
@Test
public void closeServerSocket() throws IOException {
ServerSocket socket = mock(ServerSocket.class);
this.subject.close(socket);
verify(socket).close();
}
@Test
public void closeDatagramSocket() {
DatagramSocket socket = mock(DatagramSocket.class);
this.subject.close(socket);
verify(socket).close();
}
@Test
public void closeMulticastSocket() {
MulticastSocket socket = mock(MulticastSocket.class);
this.subject.close(socket);
verify(socket).close();
}
}
| 23,903
| 42.304348
| 233
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/test/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsTransformersTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.List;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.subsystem.AdditionalInitialization;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.model.test.FailedOperationTransformationConfig;
import org.jboss.as.model.test.ModelTestControllerVersion;
import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.as.subsystem.test.KernelServicesBuilder;
import org.jboss.dmr.ModelNode;
import org.jgroups.conf.ClassConfigurator;
import org.junit.Assert;
import org.junit.Test;
/**
* Test cases for transformers used in the JGroups subsystem.
*
* @author <a href="tomaz.cerar@redhat.com">Tomaz Cerar</a>
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
* @author Radoslav Husar
*/
public class JGroupsTransformersTestCase extends OperationTestCaseBase {
private static String formatArtifact(String pattern, ModelTestControllerVersion version) {
return String.format(pattern, version.getMavenGavVersion());
}
private static JGroupsSubsystemModel getModelVersion(ModelTestControllerVersion controllerVersion) {
switch (controllerVersion) {
case EAP_7_4_0:
return JGroupsSubsystemModel.VERSION_8_0_0;
default:
throw new IllegalArgumentException();
}
}
private static String[] getDependencies(ModelTestControllerVersion version) {
switch (version) {
case EAP_7_4_0:
return new String[] {
formatArtifact("org.jboss.eap:wildfly-clustering-jgroups-extension:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-api:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-common:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-jgroups-spi:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-server:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-service:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-spi:%s", version),
};
default:
throw new IllegalArgumentException();
}
}
private static org.jboss.as.subsystem.test.AdditionalInitialization createAdditionalInitialization() {
return new AdditionalInitialization()
.require(CommonUnaryRequirement.SOCKET_BINDING, "jgroups-tcp", "jgroups-udp", "jgroups-udp-fd", "some-binding", "client-binding", "jgroups-diagnostics", "jgroups-mping", "jgroups-tcp-fd", "jgroups-client-fd", "jgroups-state-xfr")
.require(CommonUnaryRequirement.KEY_STORE, "my-key-store")
.require(CommonUnaryRequirement.CREDENTIAL_STORE, "my-credential-store")
;
}
@Test
public void testTransformerEAP740() throws Exception {
testTransformation(ModelTestControllerVersion.EAP_7_4_0);
}
/**
* Tests transformation of model from current version into specified version.
*/
private void testTransformation(final ModelTestControllerVersion controller) throws Exception {
final ModelVersion version = getModelVersion(controller).getVersion();
final String[] dependencies = getDependencies(controller);
final String subsystemXmlResource = String.format("subsystem-jgroups-transform-%d_%d_%d.xml", version.getMajor(), version.getMinor(), version.getMicro());
// create builder for current subsystem version
KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization())
.setSubsystemXmlResource(subsystemXmlResource);
// initialize the legacy services and add required jars
builder.createLegacyKernelServicesBuilder(createAdditionalInitialization(), controller, version)
.addMavenResourceURL(dependencies)
.addSingleChildFirstClass(AdditionalInitialization.class)
// workaround IllegalArgumentException: key 1100 (org.jboss.as.clustering.jgroups.auth.BinaryAuthToken) is already in magic map; make sure that all keys are unique
.addSingleChildFirstClass(ClassConfigurator.class)
.skipReverseControllerCheck()
.dontPersistXml();
KernelServices services = builder.build();
Assert.assertTrue(services.isSuccessfulBoot());
Assert.assertTrue(services.getLegacyServices(version).isSuccessfulBoot());
// check that both versions of the legacy model are the same and valid
checkSubsystemModelTransformation(services, version, null, false);
}
@Test
public void testRejectionsEAP740() throws Exception {
testRejections(ModelTestControllerVersion.EAP_7_4_0);
}
private void testRejections(final ModelTestControllerVersion controller) throws Exception {
final ModelVersion version = getModelVersion(controller).getVersion();
final String[] dependencies = getDependencies(controller);
// create builder for current subsystem version
KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization());
// initialize the legacy services and add required jars
builder.createLegacyKernelServicesBuilder(createAdditionalInitialization(), controller, version)
.addSingleChildFirstClass(AdditionalInitialization.class)
.addMavenResourceURL(dependencies)
// workaround IllegalArgumentException: key 1100 (org.jboss.as.clustering.jgroups.auth.BinaryAuthToken) is already in magic map; make sure that all keys are unique
.addSingleChildFirstClass(ClassConfigurator.class)
.dontPersistXml();
KernelServices services = builder.build();
Assert.assertTrue(services.isSuccessfulBoot());
KernelServices legacyServices = services.getLegacyServices(version);
Assert.assertNotNull(legacyServices);
Assert.assertTrue(legacyServices.isSuccessfulBoot());
List<ModelNode> operations = builder.parseXmlResource("subsystem-jgroups-transform-reject.xml");
ModelTestUtils.checkFailedTransformedBootOperations(services, version, operations, createFailedOperationTransformationConfig(version));
}
private static FailedOperationTransformationConfig createFailedOperationTransformationConfig(ModelVersion version) {
FailedOperationTransformationConfig config = new FailedOperationTransformationConfig();
PathAddress subsystemAddress = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
if (JGroupsSubsystemModel.VERSION_8_0_0.requiresTransformation(version)) {
config.addFailedAttribute(subsystemAddress.append(StackResourceDefinition.pathElement("credentialReference1")).append(ProtocolResourceDefinition.pathElement("SYM_ENCRYPT")),
FailedOperationTransformationConfig.REJECTED_RESOURCE);
}
return config;
}
}
| 8,283
| 49.206061
| 245
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/test/java/org/jboss/as/clustering/jgroups/subsystem/OperationSequencesTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILED;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
import java.util.List;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
/**
* Test case for testing sequences of management operations.
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
*/
public class OperationSequencesTestCase extends OperationTestCaseBase {
// stack test operations
static final ModelNode addStackOp = getProtocolStackAddOperation("maximal2");
// addStackOpWithParams calls the operation below to check passing optional parameters
// /subsystem=jgroups/stack=maximal2:add(transport={type=UDP},protocols=[{type=MPING},{type=FLUSH}])
static final ModelNode addStackOpWithParams = getProtocolStackAddOperationWithParameters("maximal2");
static final ModelNode removeStackOp = getProtocolStackRemoveOperation("maximal2");
// transport test operations
static final ModelNode addTransportOp = getTransportAddOperation("maximal2", "UDP");
static final ModelNode removeTransportOp = getTransportRemoveOperation("maximal2", "UDP");
// protocol test operations
static final ModelNode addProtocolOp = getProtocolAddOperation("maximal2", "PING");
static final ModelNode removeProtocolOp = getProtocolRemoveOperation("maximal2", "PING");
@Test
public void testProtocolStackAddRemoveAddSequence() throws Exception {
KernelServices services = buildKernelServices();
ModelNode operation = Util.createCompositeOperation(List.of(addStackOp, addTransportOp, addProtocolOp));
// add a protocol stack, its transport and a protocol as a batch
ModelNode result = services.executeOperation(operation);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
// remove the stack
result = services.executeOperation(removeStackOp);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
// add the same stack
result = services.executeOperation(operation);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
}
@Test
public void testProtocolStackRemoveRemoveSequence() throws Exception {
KernelServices services = buildKernelServices();
ModelNode operation = Util.createCompositeOperation(List.of(addStackOp, addTransportOp, addProtocolOp));
// add a protocol stack
ModelNode result = services.executeOperation(operation);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
// remove the protocol stack
result = services.executeOperation(removeStackOp);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
// remove the protocol stack again
result = services.executeOperation(removeStackOp);
Assert.assertEquals(FAILED, result.get(OUTCOME).asString());
}
/**
* Tests the ability of the /subsystem=jgroups/stack=X:add() operation
* to correctly process the optional TRANSPORT and PROTOCOLS parameters.
*/
@Test
public void testProtocolStackAddRemoveSequenceWithParameters() throws Exception {
KernelServices services = buildKernelServices();
// add a protocol stack specifying TRANSPORT and PROTOCOLS parameters
ModelNode result = services.executeOperation(addStackOpWithParams);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
// check some random values
// remove the protocol stack
result = services.executeOperation(removeStackOp);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
// remove the protocol stack again
result = services.executeOperation(removeStackOp);
Assert.assertEquals(FAILED, result.get(OUTCOME).asString());
}
}
| 5,163
| 41.677686
| 112
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/test/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.subsystem.AdditionalInitialization;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.as.subsystem.test.AbstractSubsystemSchemaTest;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.as.subsystem.test.KernelServicesBuilder;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Tests parsing / booting / marshalling of JGroups configurations.
*
* The current XML configuration is tested, along with supported legacy configurations.
*
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
* @author Richard Achmatowicz (c) 2013 Red Hat Inc.
*/
@RunWith(value = Parameterized.class)
public class JGroupsSubsystemTestCase extends AbstractSubsystemSchemaTest<JGroupsSubsystemSchema> {
@Parameters
public static Iterable<JGroupsSubsystemSchema> parameters() {
return EnumSet.allOf(JGroupsSubsystemSchema.class);
}
private final JGroupsSubsystemSchema schema;
public JGroupsSubsystemTestCase(JGroupsSubsystemSchema schema) {
super(JGroupsExtension.SUBSYSTEM_NAME, new JGroupsExtension(), schema, JGroupsSubsystemSchema.CURRENT);
this.schema = schema;
}
@Override
protected String getSubsystemXsdPathPattern() {
return "schema/jboss-as-%s_%d_%d.xsd";
}
private KernelServices buildKernelServices() throws Exception {
return this.buildKernelServices(this.getSubsystemXml());
}
private KernelServices buildKernelServices(String xml) throws Exception {
return this.createKernelServicesBuilder(xml).build();
}
private KernelServicesBuilder createKernelServicesBuilder() {
return this.createKernelServicesBuilder(this.createAdditionalInitialization());
}
private KernelServicesBuilder createKernelServicesBuilder(String xml) throws XMLStreamException {
return this.createKernelServicesBuilder().setSubsystemXml(xml);
}
@Override
protected org.jboss.as.subsystem.test.AdditionalInitialization createAdditionalInitialization() {
return new AdditionalInitialization()
.require(CommonUnaryRequirement.SOCKET_BINDING, "jgroups-tcp", "jgroups-udp", "some-binding", "jgroups-diagnostics", "jgroups-mping", "jgroups-tcp-fd", "jgroups-client-fd")
.require(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING, "node1", "node2")
.require(CommonUnaryRequirement.KEY_STORE, "my-key-store")
.require(CommonUnaryRequirement.CREDENTIAL_STORE, "my-credential-store")
.require(CommonUnaryRequirement.DATA_SOURCE, "ExampleDS")
;
}
/**
* Tests that the 'fork' and 'stack' resources allow indexed adds for the 'protocol' children. This is important for
* the work being done for WFCORE-401. This work involves calculating the operations to bring the secondary Host Controller's domain model
* into sync with the primary Host Controller's domain model. Without ordered resources, that would mean on reconnect if the primary
* had added a protocol somewhere in the middle, the protocol would get added to the end rather at the correct place.
*/
@Test
public void testIndexedAdds() throws Exception {
if (!this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) return;
final KernelServices services = this.buildKernelServices();
ModelNode originalSubsystemModel = services.readWholeModel().get(JGroupsSubsystemResourceDefinition.PATH.getKeyValuePair());
ModelNode originalChannelModel = originalSubsystemModel.get(ChannelResourceDefinition.pathElement("ee").getKeyValuePair());
ModelNode originalForkModel = originalChannelModel.get(ForkResourceDefinition.pathElement("web").getKeyValuePair());
Assert.assertTrue(originalForkModel.isDefined());
originalForkModel.protect();
Assert.assertTrue(0 < originalForkModel.get(ProtocolResourceDefinition.WILDCARD_PATH.getKey()).keys().size());
ModelNode originalStackModel = originalSubsystemModel.get(StackResourceDefinition.pathElement("maximal").getKeyValuePair());
Assert.assertTrue(originalStackModel.isDefined());
originalStackModel.protect();
final PathAddress subsystemAddress = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
final PathAddress forkAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement("ee")).append(ForkResourceDefinition.pathElement("web"));
final PathAddress stackAddress = subsystemAddress.append(StackResourceDefinition.pathElement("maximal"));
//Check the fork protocols honour indexed adds by inserting a protocol at the start
ModelNode add = Util.createAddOperation(forkAddress.append(ProtocolResourceDefinition.pathElement("MERGE3")), 0);
ModelTestUtils.checkOutcome(services.executeOperation(add));
ModelNode subsystemModel = services.readWholeModel().get(JGroupsSubsystemResourceDefinition.PATH.getKeyValuePair());
ModelNode channelModel = subsystemModel.get(ChannelResourceDefinition.pathElement("ee").getKeyValuePair());
ModelNode forkModel = channelModel.get(ForkResourceDefinition.pathElement("web").getKeyValuePair());
Assert.assertEquals(originalForkModel.keys().size() + 1, forkModel.get(ProtocolResourceDefinition.WILDCARD_PATH.getKey()).keys().size());
Assert.assertEquals("MERGE3", forkModel.get(ProtocolResourceDefinition.WILDCARD_PATH.getKey()).keys().iterator().next());
//Check the stack protocols honour indexed adds by removing a protocol in the middle and readding it
ModelNode remove = Util.createRemoveOperation(stackAddress.append(ProtocolResourceDefinition.pathElement("FD")));
ModelTestUtils.checkOutcome(services.executeOperation(remove));
add = Util.createAddOperation(stackAddress.append(ProtocolResourceDefinition.pathElement("FD")), 3); //The original index of the FD protocol
ModelTestUtils.checkOutcome(services.executeOperation(add));
subsystemModel = services.readWholeModel().get(JGroupsSubsystemResourceDefinition.PATH.getKeyValuePair());
ModelNode stackModel = subsystemModel.get(StackResourceDefinition.pathElement("maximal").getKeyValuePair());
Assert.assertEquals(originalStackModel, stackModel);
}
}
| 7,790
| 51.288591
| 188
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/test/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemInitialization.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.subsystem.AdditionalInitialization;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry;
import org.jboss.as.controller.extension.ExtensionRegistry;
import org.jboss.as.controller.extension.ExtensionRegistryType;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
/**
* Initializer for the JGroups subsystem.
* @author Paul Ferraro
*/
public class JGroupsSubsystemInitialization extends AdditionalInitialization {
private static final long serialVersionUID = -4433079373360352449L;
public JGroupsSubsystemInitialization() {
super();
}
public JGroupsSubsystemInitialization(RunningMode mode) {
super(mode);
}
@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry registry, Resource root, ManagementResourceRegistration registration, RuntimeCapabilityRegistry capabilityRegistry) {
new JGroupsExtension().initialize(registry.getExtensionContext("jgroups", registration, ExtensionRegistryType.MASTER));
Resource subsystem = Resource.Factory.create();
// Need to use explicit names here due to signature change ("NoSuchMethodError: org.jboss.as.clustering.jgroups.subsystem.JGroupsSubsystemResourceDefinition$Attribute.getName()Ljava/lang/String;")
subsystem.getModel().get("default-stack").set("tcp");
subsystem.getModel().get("default-channel").set("maximal-channel");
root.registerChild(JGroupsSubsystemResourceDefinition.PATH, subsystem);
Resource channel = Resource.Factory.create();
subsystem.registerChild(ChannelResourceDefinition.pathElement("maximal-channel"), channel);
Resource stack = Resource.Factory.create();
subsystem.registerChild(StackResourceDefinition.pathElement("tcp"), stack);
Resource transport = Resource.Factory.create();
stack.registerChild(TransportResourceDefinition.pathElement("TCP"), transport);
super.initializeExtraSubystemsAndModel(registry, root, registration, capabilityRegistry);
}
}
| 3,250
| 46.808824
| 204
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/test/java/org/jboss/as/clustering/jgroups/subsystem/OperationTestCaseBase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.io.IOException;
import java.util.List;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.subsystem.AdditionalInitialization;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.subsystem.test.AbstractSubsystemTest;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.dmr.ModelNode;
/**
* Base test case for testing management operations.
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
*/
public class OperationTestCaseBase extends AbstractSubsystemTest {
static final String SUBSYSTEM_XML_FILE = String.format("jgroups-%d.%d.xml", JGroupsSubsystemSchema.CURRENT.getVersion().major(), JGroupsSubsystemSchema.CURRENT.getVersion().minor());
public OperationTestCaseBase() {
super(JGroupsExtension.SUBSYSTEM_NAME, new JGroupsExtension());
}
protected static ModelNode getSubsystemAddOperation(String defaultStack) {
return Util.createAddOperation(getSubsystemAddress());
}
protected static ModelNode getSubsystemReadOperation(Attribute attribute) {
return Util.getReadAttributeOperation(getSubsystemAddress(), attribute.getName());
}
protected static ModelNode getSubsystemWriteOperation(Attribute attribute, String value) {
return Util.getWriteAttributeOperation(getSubsystemAddress(), attribute.getName(), new ModelNode(value));
}
protected static ModelNode getSubsystemRemoveOperation() {
return Util.createRemoveOperation(getSubsystemAddress());
}
protected static ModelNode getProtocolStackAddOperation(String stackName) {
return Util.createAddOperation(getProtocolStackAddress(stackName));
}
protected static ModelNode getProtocolStackAddOperationWithParameters(String stackName) {
return Util.createCompositeOperation(List.of(
getProtocolStackAddOperation(stackName),
getTransportAddOperation(stackName, "UDP"),
getProtocolAddOperation(stackName, "PING"),
getProtocolAddOperation(stackName, "pbcast.FLUSH")
));
}
protected static ModelNode getProtocolStackRemoveOperation(String stackName) {
return Util.createRemoveOperation(getProtocolStackAddress(stackName));
}
protected static ModelNode getTransportAddOperation(String stackName, String protocol) {
ModelNode operation = Util.createAddOperation(getTransportAddress(stackName, protocol));
operation.get(MulticastProtocolResourceDefinition.Attribute.SOCKET_BINDING.getName()).set("some-binding");
return operation;
}
protected static ModelNode getTransportRemoveOperation(String stackName, String type) {
return Util.createRemoveOperation(getTransportAddress(stackName, type));
}
protected static ModelNode getTransportReadOperation(String stackName, String type, Attribute attribute) {
return Util.getReadAttributeOperation(getTransportAddress(stackName, type), attribute.getName());
}
protected static ModelNode getTransportWriteOperation(String stackName, String type, Attribute attribute, String value) {
return Util.getWriteAttributeOperation(getTransportAddress(stackName, type), attribute.getName(), new ModelNode(value));
}
// Transport property map operations
protected static ModelNode getTransportGetPropertyOperation(String stackName, String type, String propertyName) {
return Util.createMapGetOperation(getTransportAddress(stackName, type), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), propertyName);
}
protected static ModelNode getTransportPutPropertyOperation(String stackName, String type, String propertyName, String propertyValue) {
return Util.createMapPutOperation(getTransportAddress(stackName, type), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), propertyName, propertyValue);
}
protected static ModelNode getTransportRemovePropertyOperation(String stackName, String type, String propertyName) {
return Util.createMapRemoveOperation(getTransportAddress(stackName, type), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), propertyName);
}
protected static ModelNode getTransportClearPropertiesOperation(String stackName, String type) {
return Util.createMapClearOperation(getTransportAddress(stackName, type), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName());
}
protected static ModelNode getTransportUndefinePropertiesOperation(String stackName, String type) {
return Util.getUndefineAttributeOperation(getTransportAddress(stackName, type), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName());
}
/**
* Creates operations such as /subsystem=jgroups/stack=tcp/transport=TCP/:write-attribute(name=properties,value={a=b,c=d})".
*
* @return resulting :write-attribute operation
*/
protected static ModelNode getTransportSetPropertiesOperation(String stackName, String type, ModelNode values) {
return Util.getWriteAttributeOperation(getTransportAddress(stackName, type), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), values);
}
protected static ModelNode getThreadPoolAddOperation(String stackName, String type, String threadPoolName) {
return Util.createAddOperation(getTransportAddress(stackName, type).append("thread-pool", threadPoolName));
}
// Protocol operations
protected static ModelNode getProtocolAddOperation(String stackName, String type) {
return Util.createAddOperation(getProtocolAddress(stackName, type));
}
protected static ModelNode getProtocolReadOperation(String stackName, String protocolName, Attribute attribute) {
return Util.getReadAttributeOperation(getProtocolAddress(stackName, protocolName), attribute.getName());
}
protected static ModelNode getProtocolWriteOperation(String stackName, String protocolName, Attribute attribute, String value) {
return Util.getWriteAttributeOperation(getProtocolAddress(stackName, protocolName), attribute.getName(), new ModelNode(value));
}
protected static ModelNode getProtocolGetPropertyOperation(String stackName, String protocolName, String propertyName) {
return Util.createMapGetOperation(getProtocolAddress(stackName, protocolName), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), propertyName);
}
protected static ModelNode getProtocolPutPropertyOperation(String stackName, String protocolName, String propertyName, String propertyValue) {
return Util.createMapPutOperation(getProtocolAddress(stackName, protocolName), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), propertyName, propertyValue);
}
protected static ModelNode getProtocolRemovePropertyOperation(String stackName, String protocolName, String propertyName) {
return Util.createMapRemoveOperation(getProtocolAddress(stackName, protocolName), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), propertyName);
}
protected static ModelNode getProtocolClearPropertiesOperation(String stackName, String protocolName) {
return Util.createMapClearOperation(getProtocolAddress(stackName, protocolName), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName());
}
protected static ModelNode getProtocolUndefinePropertiesOperation(String stackName, String protocolName) {
return Util.getUndefineAttributeOperation(getProtocolAddress(stackName, protocolName), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName());
}
/**
* Creates operations such as /subsystem=jgroups/stack=tcp/protocol=MPING/:write-attribute(name=properties,value={a=b,c=d})".
*/
protected static ModelNode getProtocolSetPropertiesOperation(String stackName, String protocolName, ModelNode values) {
return Util.getWriteAttributeOperation(getProtocolAddress(stackName, protocolName), AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), values);
}
protected static ModelNode getProtocolRemoveOperation(String stackName, String type) {
return Util.createRemoveOperation(getProtocolAddress(stackName, type));
}
protected static PathAddress getSubsystemAddress() {
return PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
}
protected static PathAddress getProtocolStackAddress(String stackName) {
return getSubsystemAddress().append(StackResourceDefinition.pathElement(stackName));
}
protected static PathAddress getTransportAddress(String stackName, String type) {
return getProtocolStackAddress(stackName).append(TransportResourceDefinition.pathElement(type));
}
protected static PathAddress getProtocolAddress(String stackName, String type) {
return getProtocolStackAddress(stackName).append(ProtocolResourceDefinition.pathElement(type));
}
protected String getSubsystemXml() throws IOException {
return readResource(SUBSYSTEM_XML_FILE) ;
}
protected KernelServices buildKernelServices() throws Exception {
return createKernelServicesBuilder(new AdditionalInitialization().require(CommonUnaryRequirement.SOCKET_BINDING, "some-binding", "jgroups-diagnostics", "jgroups-mping", "jgroups-tcp-fd", "new-socket-binding")).setSubsystemXml(this.getSubsystemXml()).build();
}
}
| 10,673
| 51.841584
| 266
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/test/java/org/jboss/as/clustering/jgroups/subsystem/OperationsTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
import org.jboss.as.controller.ExpressionResolver;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
/**
* Test case for testing individual management operations.
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
*/
public class OperationsTestCase extends OperationTestCaseBase {
/**
* Tests access to subsystem attributes
*/
@Test
public void testSubsystemReadWriteOperations() throws Exception {
KernelServices services = this.buildKernelServices();
// read the default stack
ModelNode result = services.executeOperation(getSubsystemReadOperation(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL));
Assert.assertEquals(result.get(FAILURE_DESCRIPTION).asString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("ee", result.get(RESULT).asString());
// write the default stack
result = services.executeOperation(getSubsystemWriteOperation(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL, "bridge"));
Assert.assertEquals(result.get(FAILURE_DESCRIPTION).asString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the default stack
result = services.executeOperation(getSubsystemReadOperation(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL));
Assert.assertEquals(result.get(FAILURE_DESCRIPTION).asString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("bridge", result.get(RESULT).asString());
}
/**
* Tests access to transport attributes
*/
@Test
public void testTransportReadWriteOperation() throws Exception {
KernelServices services = this.buildKernelServices();
// read the transport rack attribute
ModelNode result = services.executeOperation(getTransportReadOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("rack1", ExpressionResolver.TEST_RESOLVER.resolveExpressions(result.get(RESULT)).asString());
// write the rack attribute
result = services.executeOperation(getTransportWriteOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK, "new-rack"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the rack attribute
result = services.executeOperation(getTransportReadOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("new-rack", result.get(RESULT).asString());
}
@Test
public void testTransportReadWriteWithParameters() throws Exception {
// Parse and install the XML into the controller
KernelServices services = this.buildKernelServices();
Assert.assertTrue("Could not create services", services.isSuccessfulBoot());
// add a protocol stack specifying TRANSPORT and PROTOCOLS parameters
ModelNode result = services.executeOperation(getProtocolStackAddOperationWithParameters("maximal2"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// write the rack attribute
result = services.executeOperation(getTransportWriteOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK, "new-rack"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the rack attribute
result = services.executeOperation(getTransportReadOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("new-rack", result.get(RESULT).asString());
}
@Test
public void testTransportPropertyReadWriteOperation() throws Exception {
KernelServices services = this.buildKernelServices();
// read the enable_bundling transport property
ModelNode result = services.executeOperation(getTransportGetPropertyOperation("maximal", "TCP", "enable_bundling"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("true", ExpressionResolver.TEST_RESOLVER.resolveExpressions(result.get(RESULT)).asString());
// write the enable_bundling transport property
result = services.executeOperation(getTransportPutPropertyOperation("maximal", "TCP", "enable_bundling", "false"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the enable_bundling transport property
result = services.executeOperation(getTransportGetPropertyOperation("maximal", "TCP", "enable_bundling"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("false", result.get(RESULT).asString());
// remove the enable_bundling transport property
result = services.executeOperation(getTransportRemovePropertyOperation("maximal", "TCP", "enable_bundling"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the enable_bundling transport property
result = services.executeOperation(getTransportGetPropertyOperation("maximal", "TCP", "enable_bundling"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertFalse(result.get(RESULT).isDefined());
}
@Test
public void testProtocolReadWriteOperation() throws Exception {
KernelServices services = this.buildKernelServices();
// add a protocol stack specifying TRANSPORT and PROTOCOLS parameters
ModelNode result = services.executeOperation(getProtocolStackAddOperationWithParameters("maximal2"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// read the socket binding attribute
result = services.executeOperation(getProtocolReadOperation("maximal", "MPING", MulticastProtocolResourceDefinition.Attribute.SOCKET_BINDING));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("jgroups-mping", result.get(RESULT).asString());
// write the attribute
result = services.executeOperation(getProtocolWriteOperation("maximal", "MPING", MulticastProtocolResourceDefinition.Attribute.SOCKET_BINDING, "new-socket-binding"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the attribute
result = services.executeOperation(getProtocolReadOperation("maximal", "MPING", MulticastProtocolResourceDefinition.Attribute.SOCKET_BINDING));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("new-socket-binding", result.get(RESULT).asString());
}
@Test
public void testProtocolPropertyReadWriteOperation() throws Exception {
KernelServices services = this.buildKernelServices();
// read the name protocol property
ModelNode result = services.executeOperation(getProtocolGetPropertyOperation("maximal", "MPING", "name"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("value", ExpressionResolver.TEST_RESOLVER.resolveExpressions(result.get(RESULT)).asString());
// write the property
result = services.executeOperation(getProtocolPutPropertyOperation("maximal", "MPING", "name", "new-value"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the property
result = services.executeOperation(getProtocolGetPropertyOperation("maximal", "MPING", "name"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertEquals("new-value", result.get(RESULT).asString());
// remove the property
result = services.executeOperation(getProtocolRemovePropertyOperation("maximal", "MPING", "name"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
// re-read the property
result = services.executeOperation(getProtocolGetPropertyOperation("maximal", "MPING", "name"));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
Assert.assertFalse(result.get(RESULT).isDefined());
}
@Test
public void testLegacyProtocolAddRemoveOperation() throws Exception {
KernelServices services = this.buildKernelServices();
testProtocolAddRemoveOperation(services, "MERGE2");
testProtocolAddRemoveOperation(services, "pbcast.NAKACK");
testProtocolAddRemoveOperation(services, "UNICAST2");
}
private static void testProtocolAddRemoveOperation(KernelServices services, String protocol) {
ModelNode result = services.executeOperation(getProtocolAddOperation("minimal", protocol));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
result = services.executeOperation(getProtocolRemoveOperation("minimal", protocol));
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
}
}
| 10,991
| 52.882353
| 174
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/ForkChannelFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.network.SocketBindingManager;
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.fork.ForkChannel;
import org.jgroups.protocols.TP;
import org.jgroups.stack.Protocol;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;
import org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration;
import org.wildfly.clustering.jgroups.spi.RelayConfiguration;
import org.wildfly.clustering.jgroups.spi.TransportConfiguration;
/**
* Factory for creating forked channels.
* @author Paul Ferraro
*/
public class ForkChannelFactory implements ChannelFactory {
private final ChannelFactory parentFactory;
private final List<ProtocolConfiguration<? extends Protocol>> protocols;
private final JChannel channel;
public ForkChannelFactory(JChannel channel, ChannelFactory parentFactory, List<ProtocolConfiguration<? extends Protocol>> protocols) {
this.channel = channel;
this.parentFactory = parentFactory;
this.protocols = protocols;
}
@Override
public JChannel createChannel(String id) throws Exception {
JGroupsLogger.ROOT_LOGGER.debugf("Creating fork channel %s from channel %s", id, this.channel.getClusterName());
String stackName = this.protocols.isEmpty() ? this.channel.getClusterName() : id;
Protocol[] protocols = new Protocol[this.protocols.size()];
for (int i = 0; i < protocols.length; ++i) {
protocols[i] = this.protocols.get(i).createProtocol(this.parentFactory.getProtocolStackConfiguration());
}
return new ForkChannel(this.channel, stackName, id, protocols);
}
@Override
public ProtocolStackConfiguration getProtocolStackConfiguration() {
ProtocolStackConfiguration parentStack = this.parentFactory.getProtocolStackConfiguration();
return new ForkProtocolStackConfiguration(this.channel.getClusterName(), parentStack, Stream.concat(parentStack.getProtocols().stream(), this.protocols.stream()).collect(Collectors.toList()));
}
@Override
public boolean isUnknownForkResponse(Message response) {
return this.parentFactory.isUnknownForkResponse(response);
}
private static class ForkProtocolStackConfiguration implements ProtocolStackConfiguration {
private final String name;
private final List<ProtocolConfiguration<? extends Protocol>> protocols;
private final ProtocolStackConfiguration parentStack;
ForkProtocolStackConfiguration(String name, ProtocolStackConfiguration parentStack, List<ProtocolConfiguration<? extends Protocol>> protocols) {
this.name = name;
this.protocols = protocols;
this.parentStack = parentStack;
}
@Override
public String getName() {
return this.name;
}
@Override
public boolean isStatisticsEnabled() {
return this.parentStack.isStatisticsEnabled();
}
@Override
public List<ProtocolConfiguration<? extends Protocol>> getProtocols() {
return this.protocols;
}
@Override
public TransportConfiguration<? extends TP> getTransport() {
return this.parentStack.getTransport();
}
@Override
public String getNodeName() {
return this.parentStack.getNodeName();
}
@Override
public Optional<RelayConfiguration> getRelay() {
return this.parentStack.getRelay();
}
@Override
public SocketBindingManager getSocketBindingManager() {
return this.parentStack.getSocketBindingManager();
}
}
}
| 4,987
| 37.369231
| 200
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/ClassLoaderThreadFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import org.jgroups.util.ThreadFactory;
import org.wildfly.clustering.context.ContextClassLoaderReference;
import org.wildfly.clustering.context.ContextReferenceExecutor;
import org.wildfly.clustering.context.Contextualizer;
/**
* {@link ThreadFactory} decorator that associates a specific class loader to created threads.
* @author Paul Ferraro
*/
public class ClassLoaderThreadFactory implements org.jgroups.util.ThreadFactory {
private final ThreadFactory factory;
private final ClassLoader targetLoader;
private final Contextualizer contextualizer;
public ClassLoaderThreadFactory(ThreadFactory factory, ClassLoader targetLoader) {
this.factory = factory;
this.targetLoader = targetLoader;
this.contextualizer = new ContextReferenceExecutor<>(targetLoader, ContextClassLoaderReference.INSTANCE);
}
@Override
public Thread newThread(Runnable runner) {
return this.newThread(runner, null);
}
@Override
public Thread newThread(final Runnable runner, String name) {
Thread thread = this.factory.newThread(this.contextualizer.contextualize(runner), name);
ContextClassLoaderReference.INSTANCE.accept(thread, this.targetLoader);
return thread;
}
@Override
public void setPattern(String pattern) {
this.factory.setPattern(pattern);
}
@Override
public void setIncludeClusterName(boolean includeClusterName) {
this.factory.setIncludeClusterName(includeClusterName);
}
@Override
public void setClusterName(String channelName) {
this.factory.setClusterName(channelName);
}
@Override
public void setAddress(String address) {
this.factory.setAddress(address);
}
@Override
public void renameThread(String base_name, Thread thread) {
this.factory.renameThread(base_name, thread);
}
}
| 2,950
| 34.987805
| 113
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/ProtocolDefaults.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import java.util.Map;
import org.jgroups.stack.Protocol;
/**
* @author Paul Ferraro
*/
public interface ProtocolDefaults {
Map<String, String> getProperties(Class<? extends Protocol> protocolClass);
}
| 1,274
| 36.5
| 79
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/ManagedSocketFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import java.io.Closeable;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.MulticastSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.channels.NetworkChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.BiFunction;
import org.jboss.as.network.SocketBinding;
import org.jboss.as.network.SocketBindingManager;
import org.jgroups.util.Util;
import org.wildfly.common.function.ExceptionFunction;
/**
* Manages registration of all JGroups sockets with a {@link SocketBindingManager}.
* @author Paul Ferraro
*/
public class ManagedSocketFactory implements SocketFactory {
private final SelectorProvider provider;
private final SocketBindingManager manager;
// Maps a JGroups service name its associated SocketBinding
private final Map<String, SocketBinding> bindings;
// Store references to managed socket-binding registrations
private final Map<NetworkChannel, Closeable> channels = Collections.synchronizedMap(new IdentityHashMap<>());
public ManagedSocketFactory(SelectorProvider provider, SocketBindingManager manager, Map<String, SocketBinding> socketBindings) {
this.provider = provider;
this.manager = manager;
this.bindings = socketBindings;
}
@Override
public Socket createSocket(String name) throws IOException {
SocketBinding binding = this.bindings.get(name);
org.jboss.as.network.ManagedSocketFactory factory = this.manager.getSocketFactory();
return (binding != null) ? factory.createSocket(binding.getName()) : factory.createSocket();
}
@Override
public ServerSocket createServerSocket(String name) throws IOException {
SocketBinding binding = this.bindings.get(name);
org.jboss.as.network.ManagedServerSocketFactory factory = this.manager.getServerSocketFactory();
return (binding != null) ? factory.createServerSocket(binding.getName()) : factory.createServerSocket();
}
@Override
public DatagramSocket createDatagramSocket(String name, SocketAddress bindAddress) throws SocketException {
SocketBinding binding = this.bindings.get(name);
if (bindAddress == null) {
// Creates unbound socket
return (binding != null) ? this.manager.createDatagramSocket(binding.getName()) : this.manager.createDatagramSocket();
}
return (binding != null) ? this.manager.createDatagramSocket(binding.getName(), bindAddress) : this.manager.createDatagramSocket(bindAddress);
}
@Override
public MulticastSocket createMulticastSocket(String name, SocketAddress bindAddress) throws IOException {
SocketBinding binding = this.bindings.get(name);
if (bindAddress == null) {
// Creates unbound socket
return (binding != null) ? this.manager.createMulticastSocket(binding.getName()) : this.manager.createMulticastSocket();
}
return (binding != null) ? this.manager.createMulticastSocket(binding.getName(), bindAddress) : this.manager.createMulticastSocket(bindAddress);
}
@Override
public SocketChannel createSocketChannel(String name) throws IOException {
return this.createNetworkChannel(name, SelectorProvider::openSocketChannel, SocketBindingManager.NamedManagedBindingRegistry::registerChannel, SocketBindingManager.UnnamedBindingRegistry::registerChannel);
}
@Override
public ServerSocketChannel createServerSocketChannel(String name) throws IOException {
return this.createNetworkChannel(name, SelectorProvider::openServerSocketChannel, SocketBindingManager.NamedManagedBindingRegistry::registerChannel, SocketBindingManager.UnnamedBindingRegistry::registerChannel);
}
@Override
public void close(SocketChannel channel) {
this.closeNetworkChannel(channel);
}
@Override
public void close(ServerSocketChannel channel) {
this.closeNetworkChannel(channel);
}
private <C extends NetworkChannel> C createNetworkChannel(String name, ExceptionFunction<SelectorProvider, C, IOException> factory, TriFunction<SocketBindingManager.NamedManagedBindingRegistry, String, C, Closeable> namedRegistration, BiFunction<SocketBindingManager.UnnamedBindingRegistry, C, Closeable> unnamedRegistration) throws IOException {
SocketBinding binding = this.bindings.get(name);
C channel = factory.apply(this.provider);
this.channels.put(channel, (binding != null) ? namedRegistration.apply(this.manager.getNamedRegistry(), binding.getName(), channel) : unnamedRegistration.apply(this.manager.getUnnamedRegistry(), channel));
return channel;
}
private void closeNetworkChannel(NetworkChannel channel) {
Util.close(this.channels.remove(channel));
Util.close(channel);
}
private static interface TriFunction<T, U, V, R> {
R apply(T t, U u, V v);
}
}
| 6,239
| 45.222222
| 350
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/TopologyAddressGenerator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import org.jgroups.Address;
import org.jgroups.stack.AddressGenerator;
import org.jgroups.util.ExtendedUUID;
import org.jgroups.util.Util;
import org.wildfly.clustering.jgroups.spi.TransportConfiguration;
/**
* An AddressGenerator which generates ExtendedUUID addresses with specified site, rack and machine ids.
*
* @author Tristan Tarrant
* @author Paul Ferraro
*/
public class TopologyAddressGenerator implements AddressGenerator {
// Based on org.jgroups.util.TopologyUUID from JGroups 3.4.x
private static final byte[] SITE = Util.stringToBytes("site-id");
private static final byte[] RACK = Util.stringToBytes("rack-id");
private static final byte[] MACHINE = Util.stringToBytes("machine-id");
private final TransportConfiguration.Topology topology;
public TopologyAddressGenerator(TransportConfiguration.Topology topology) {
this.topology = topology;
}
@Override
public Address generateAddress() {
ExtendedUUID uuid = ExtendedUUID.randomUUID();
uuid.put(SITE, Util.stringToBytes(this.topology.getSite()));
uuid.put(RACK, Util.stringToBytes(this.topology.getRack()));
uuid.put(MACHINE, Util.stringToBytes(this.topology.getMachine()));
return uuid;
}
}
| 2,320
| 39.719298
| 104
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/SocketFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import org.jgroups.util.Util;
/**
* Provides default implementations for most {@link org.jgroups.util.SocketFactory} methods.
* @author Paul Ferraro
*/
public interface SocketFactory extends org.jgroups.util.SocketFactory {
static final int DEFAULT_BACKLOG = 0;
static final int DEFAULT_BIND_PORT = 0;
@Override
default Socket createSocket(String name, String host, int port) throws IOException {
return this.createSocket(name, new InetSocketAddress(host, port), null);
}
@Override
default Socket createSocket(String name, InetAddress address, int port) throws IOException {
return this.createSocket(name, new InetSocketAddress(address, port), null);
}
@Override
default Socket createSocket(String name, String host, int port, InetAddress bindAddress, int bindPort) throws IOException {
return this.createSocket(name, new InetSocketAddress(host, port), new InetSocketAddress(bindAddress, bindPort));
}
@Override
default Socket createSocket(String name, InetAddress address, int port, InetAddress bindAddress, int bindPort) throws IOException {
return this.createSocket(name, new InetSocketAddress(address, port), new InetSocketAddress(bindAddress, bindPort));
}
default Socket createSocket(String name, SocketAddress connectAddress, SocketAddress bindAddress) throws IOException {
Socket socket = this.createSocket(name);
try {
if (bindAddress != null) {
socket.bind(bindAddress);
}
socket.connect(connectAddress);
} catch (IOException e) {
this.close(socket);
throw e;
}
return socket;
}
@Override
default ServerSocket createServerSocket(String name, int port) throws IOException {
return this.createServerSocket(name, port, DEFAULT_BACKLOG);
}
@Override
default ServerSocket createServerSocket(String name, int port, int backlog) throws IOException {
return this.createServerSocket(name, new InetSocketAddress(port), backlog);
}
@Override
default ServerSocket createServerSocket(String name, int port, int backlog, InetAddress address) throws IOException {
return this.createServerSocket(name, new InetSocketAddress(address, port), backlog);
}
default ServerSocket createServerSocket(String name, SocketAddress bindAddress, int backlog) throws IOException {
ServerSocket socket = this.createServerSocket(name);
try {
socket.bind(bindAddress, backlog);
} catch (IOException e) {
this.close(socket);
throw e;
}
return socket;
}
@Override
default SocketChannel createSocketChannel(String name, SocketAddress bindAddress) throws IOException {
SocketChannel channel = this.createSocketChannel(name);
try {
channel.bind(bindAddress);
} catch (IOException e) {
this.close(channel);
throw e;
}
return channel;
}
@Override
default ServerSocketChannel createServerSocketChannel(String name, int port) throws IOException {
return this.createServerSocketChannel(name, port, DEFAULT_BACKLOG);
}
@Override
default ServerSocketChannel createServerSocketChannel(String name, int port, int backlog) throws IOException {
return this.createServerSocketChannel(name, new InetSocketAddress(port), backlog);
}
@Override
default ServerSocketChannel createServerSocketChannel(String name, int port, int backlog, InetAddress address) throws IOException {
return this.createServerSocketChannel(name, new InetSocketAddress(address, port), backlog);
}
default ServerSocketChannel createServerSocketChannel(String name, SocketAddress bindAddress, int backlog) throws IOException {
ServerSocketChannel channel = this.createServerSocketChannel(name);
try {
channel.bind(bindAddress, backlog);
} catch (IOException e) {
this.close(channel);
throw e;
}
return channel;
}
@Override
default DatagramSocket createDatagramSocket(String name) throws SocketException {
return this.createDatagramSocket(name, DEFAULT_BIND_PORT);
}
@Override
default DatagramSocket createDatagramSocket(String name, int port) throws SocketException {
return this.createDatagramSocket(name, new InetSocketAddress(port));
}
@Override
default DatagramSocket createDatagramSocket(String name, int port, InetAddress address) throws SocketException {
return this.createDatagramSocket(name, new InetSocketAddress(address, port));
}
@Override
default MulticastSocket createMulticastSocket(String name) throws IOException {
return this.createMulticastSocket(name, DEFAULT_BIND_PORT);
}
@Override
default MulticastSocket createMulticastSocket(String name, int port) throws IOException {
return this.createMulticastSocket(name, new InetSocketAddress(port));
}
default MulticastSocket createMulticastSocket(String name, int port, InetAddress address) throws IOException {
return this.createMulticastSocket(name, new InetSocketAddress(address, port));
}
@Override
default void close(Socket socket) throws IOException {
Util.close(socket);
}
@Override
default void close(ServerSocket socket) throws IOException {
Util.close(socket);
}
@Override
default void close(DatagramSocket socket) {
Util.close(socket);
}
}
| 7,063
| 36.178947
| 135
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/LogFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import org.jboss.logging.Logger;
import org.jboss.logging.Logger.Level;
import org.jgroups.logging.CustomLogFactory;
import org.jgroups.logging.Log;
/**
* Temporary workaround for JGRP-1475.
* @author Paul Ferraro
*/
public class LogFactory implements CustomLogFactory {
@Override
public Log getLog(Class<?> clazz) {
return new LogAdapter(Logger.getLogger(clazz));
}
@Override
public Log getLog(String category) {
return new LogAdapter(Logger.getLogger(category));
}
private static class LogAdapter implements Log {
private final Logger logger;
LogAdapter(Logger logger) {
this.logger = logger;
}
@Override
public boolean isFatalEnabled() {
return this.logger.isEnabled(Level.FATAL);
}
@Override
public boolean isErrorEnabled() {
return this.logger.isEnabled(Level.ERROR);
}
@Override
public boolean isWarnEnabled() {
return this.logger.isEnabled(Level.WARN);
}
@Override
public boolean isInfoEnabled() {
return this.logger.isInfoEnabled();
}
@Override
public boolean isDebugEnabled() {
return this.logger.isDebugEnabled();
}
@Override
public boolean isTraceEnabled() {
return this.logger.isTraceEnabled();
}
@Override
public void fatal(String msg) {
this.logger.fatal(msg);
}
@Override
public void fatal(String msg, Object... args) {
this.logger.fatalf(msg, args);
}
@Override
public void fatal(String msg, Throwable throwable) {
this.logger.fatal(msg, throwable);
}
@Override
public void error(String msg) {
this.logger.error(msg);
}
@Override
public void error(String msg, Object... args) {
this.logger.errorf(msg, args);
}
@Override
public void error(String msg, Throwable throwable) {
this.logger.error(msg, throwable);
}
@Override
public void warn(String msg) {
this.logger.warn(msg);
}
@Override
public void warn(String msg, Object... args) {
this.logger.warnf(msg, args);
}
@Override
public void warn(String msg, Throwable throwable) {
this.logger.warn(msg, throwable);
}
@Override
public void info(String msg) {
this.logger.info(msg);
}
@Override
public void info(String msg, Object... args) {
this.logger.infof(msg, args);
}
@Override
public void debug(String msg) {
this.logger.debug(msg);
}
@Override
public void debug(String msg, Object... args) {
this.logger.debugf(msg, args);
}
@Override
public void debug(String msg, Throwable throwable) {
this.logger.debug(msg, throwable);
}
@Override
public void trace(Object msg) {
this.logger.trace(msg);
}
@Override
public void trace(String msg) {
this.logger.trace(msg);
}
@Override
public void trace(String msg, Object... args) {
this.logger.tracef(msg, args);
}
@Override
public void trace(String msg, Throwable throwable) {
this.logger.trace(msg, throwable);
}
@Override
public void setLevel(String level) {
// Unsupported
}
@Override
public String getLevel() {
return null;
}
}
}
| 4,860
| 25.562842
| 70
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/JChannelFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups;
import java.nio.channels.spi.SelectorProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jboss.as.network.SocketBinding;
import org.jgroups.EmptyMessage;
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.blocks.RequestCorrelator;
import org.jgroups.blocks.RequestCorrelator.Header;
import org.jgroups.conf.ClassConfigurator;
import org.jgroups.fork.UnknownForkHandler;
import org.jgroups.protocols.FORK;
import org.jgroups.protocols.TP;
import org.jgroups.stack.Protocol;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;
import org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration;
import org.wildfly.clustering.jgroups.spi.TransportConfiguration;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* Factory for creating fork-able channels.
* @author Paul Ferraro
*/
public class JChannelFactory implements ChannelFactory {
private final ProtocolStackConfiguration configuration;
public JChannelFactory(ProtocolStackConfiguration configuration) {
this.configuration = configuration;
}
@Override
public ProtocolStackConfiguration getProtocolStackConfiguration() {
return this.configuration;
}
@Override
public JChannel createChannel(String id) throws Exception {
FORK fork = new FORK();
fork.enableStats(this.configuration.isStatisticsEnabled());
fork.setUnknownForkHandler(new UnknownForkHandler() {
private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class);
@Override
public Object handleUnknownForkStack(Message message, String forkStackId) {
return this.handle(message);
}
@Override
public Object handleUnknownForkChannel(Message message, String forkChannelId) {
return this.handle(message);
}
private Object handle(Message message) {
Header header = (Header) message.getHeader(this.id);
// If this is a request expecting a response, don't leave the requester hanging - send an identifiable response on which it can filter
if ((header != null) && (header.type == Header.REQ) && header.rspExpected()) {
Message response = new EmptyMessage(message.src()).setFlag(message.getFlags(), false).clearFlag(Message.Flag.RSVP);
if (message.getDest() != null) {
response.src(message.getDest());
}
response.putHeader(FORK.ID, message.getHeader(FORK.ID));
response.putHeader(this.id, new Header(Header.RSP, header.req_id, header.corrId));
fork.getProtocolStack().getChannel().down(response);
}
return null;
}
});
Map<String, SocketBinding> bindings = new HashMap<>();
// Transport always resides at the bottom of the stack
List<ProtocolConfiguration<? extends Protocol>> transports = Collections.singletonList(this.configuration.getTransport());
// Add RELAY2 to the top of the stack, if defined
List<ProtocolConfiguration<? extends Protocol>> relays = this.configuration.getRelay().isPresent() ? Collections.singletonList(this.configuration.getRelay().get()) : Collections.emptyList();
List<Protocol> protocols = new ArrayList<>(transports.size() + this.configuration.getProtocols().size() + relays.size() + 1);
for (List<ProtocolConfiguration<? extends Protocol>> protocolConfigs : List.of(transports, this.configuration.getProtocols(), relays)) {
for (ProtocolConfiguration<? extends Protocol> protocolConfig : protocolConfigs) {
protocols.add(protocolConfig.createProtocol(this.configuration));
bindings.putAll(protocolConfig.getSocketBindings());
}
}
// Add implicit FORK to the top of the stack
protocols.add(fork);
// Override the SocketFactory of the transport
TP transport = (TP) protocols.get(0);
transport.setSocketFactory(new ManagedSocketFactory(SelectorProvider.provider(), this.configuration.getSocketBindingManager(), bindings));
JChannel channel = createChannel(protocols);
channel.setName(this.configuration.getNodeName());
TransportConfiguration.Topology topology = this.configuration.getTransport().getTopology();
if (topology != null) {
channel.addAddressGenerator(new TopologyAddressGenerator(topology));
}
return channel;
}
// TODO Remove this once DNS_PING is configurable via an explicit DNSResolver
private static JChannel createChannel(List<Protocol> protocols) throws Exception {
// DNS_PING current loads its InitialContextFactory via the TCCL
ClassLoader loader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(JChannel.class);
return new JChannel(protocols);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(loader);
}
}
@Override
public boolean isUnknownForkResponse(Message response) {
return !response.hasPayload();
}
}
| 6,563
| 43.351351
| 198
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/auth/CipherAuthToken.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.auth;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyPair;
import java.util.Arrays;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import org.jgroups.Message;
import org.jgroups.auth.AuthToken;
/**
* An AUTH token, functionally equivalent to {@link org.jgroups.auth.X509Token}, but configured using Elytron resources.
* @author Paul Ferraro
*/
public class CipherAuthToken extends BinaryAuthToken {
private final Cipher cipher;
private final byte[] rawSharedSecret;
public CipherAuthToken() {
super();
this.cipher = null;
this.rawSharedSecret = null;
}
public CipherAuthToken(Cipher cipher, KeyPair pair, byte[] rawSharedSecret) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
super(encryptedSharedSecret(cipher, pair.getPublic(), rawSharedSecret));
this.cipher = cipher;
this.rawSharedSecret = rawSharedSecret;
this.cipher.init(Cipher.DECRYPT_MODE, pair.getPrivate());
}
private static byte[] encryptedSharedSecret(Cipher cipher, Key key, byte[] data) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(data);
}
@Override
public synchronized boolean authenticate(AuthToken token, Message message) {
if ((this.getSharedSecret() == null) || !(token instanceof CipherAuthToken)) return false;
try {
byte[] decrypted = this.cipher.doFinal(((CipherAuthToken) token).getSharedSecret());
return Arrays.equals(decrypted, this.rawSharedSecret);
} catch (GeneralSecurityException e) {
return false;
}
}
}
| 2,933
| 37.605263
| 161
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/auth/BinaryAuthToken.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.auth;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import org.jgroups.Message;
import org.jgroups.auth.AuthToken;
import org.jgroups.util.Util;
/**
* An AUTH token, analogous to {@link org.jgroups.auth.SimpleToken}, but uses a binary shared secret, instead of a case-insensitive string comparison.
* @author Paul Ferraro
*/
public class BinaryAuthToken extends AuthToken {
private volatile byte[] sharedSecret;
public BinaryAuthToken() {
this.sharedSecret = null;
}
public BinaryAuthToken(byte[] sharedSecret) {
this.sharedSecret = sharedSecret;
}
public byte[] getSharedSecret() {
return this.sharedSecret;
}
@Override
public boolean authenticate(AuthToken token, Message message) {
if ((this.sharedSecret == null) || !(token instanceof BinaryAuthToken)) return false;
return Arrays.equals(this.sharedSecret, ((BinaryAuthToken) token).sharedSecret);
}
@Override
public String getName() {
return this.getClass().getName();
}
@Override
public int size() {
return Util.size(this.sharedSecret);
}
@Override
public void writeTo(DataOutput output) throws IOException {
Util.writeByteBuffer(this.sharedSecret, output);
}
@Override
public void readFrom(DataInput input) throws IOException {
this.sharedSecret = Util.readByteBuffer(input);
}
}
| 2,536
| 30.7125
| 150
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/logging/JGroupsLogger.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.logging;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.WARN;
import java.net.InetSocketAddress;
import java.net.URL;
import java.net.UnknownHostException;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.network.OutboundSocketBinding;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jgroups.View;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
@MessageLogger(projectCode = "WFLYCLJG", length = 4)
public interface JGroupsLogger extends BasicLogger {
String ROOT_LOGGER_CATEGORY = "org.jboss.as.clustering.jgroups";
/**
* The root logger.
*/
JGroupsLogger ROOT_LOGGER = Logger.getMessageLogger(JGroupsLogger.class, ROOT_LOGGER_CATEGORY);
/**
* Logs an informational message indicating the JGroups subsystem is being activated.
*/
@LogMessage(level = INFO)
@Message(id = 1, value = "Activating JGroups subsystem. JGroups version %s")
void activatingSubsystem(String version);
// @LogMessage(level = TRACE)
// @Message(id = 2, value = "Setting %s.%s=%d")
// void setProtocolPropertyValue(String protocol, String property, Object value);
// @LogMessage(level = TRACE)
// @Message(id = 3, value = "Failed to set non-existent %s.%s=%d")
// void nonExistentProtocolPropertyValue(@Cause Throwable cause, String protocolName, String propertyName, Object propertyValue);
// @LogMessage(level = TRACE)
// @Message(id = 4, value = "Could not set %s.%s and %s.%s, %s socket binding does not specify a multicast socket")
// void couldNotSetAddressAndPortNoMulticastSocket(@Cause Throwable cause, String protocolName, String addressProperty, String protocolNameAgain, String portProperty, String bindingName);
// @LogMessage(level = ERROR)
// @Message(id = 5, value = "Error accessing original value for property %s of protocol %s")
// void unableToAccessProtocolPropertyValue(@Cause Throwable cause, String propertyName, String protocolName);
// @LogMessage(level = WARN)
// @Message(id = 6, value = "property %s for protocol %s attempting to override socket binding value %s : property value %s will be ignored")
// void unableToOverrideSocketBindingValue(String propertyName, String protocolName, String bindingName, Object propertyValue);
/**
* A message indicating a file could not be parsed.
*
* @param url the path to the file.
* @return the message.
*/
@Message(id = 7, value = "Failed to parse %s")
String parserFailure(URL url);
/**
* A message indicating a resource could not be located.
*
* @param resource the resource that could not be located.
* @return the message.
*/
@Message(id = 8, value = "Failed to locate %s")
String notFound(String resource);
// @Message(id = 9, value = "A node named %s already exists in this cluster. Perhaps there is already a server running on this host? If so, restart this server with a unique node name, via -Djboss.node.name=<node-name>")
// IllegalStateException duplicateNodeName(String name);
@Message(id = 10, value = "Transport for stack %s is not defined. Please specify both a transport and protocol list, either as optional parameters to add() or via batching.")
OperationFailedException transportNotDefined(String stackName);
// @Message(id = 11, value = "Protocol list for stack %s is not defined. Please specify both a transport and protocol list, either as optional parameters to add() or via batching.")
// OperationFailedException protocolListNotDefined(String stackName);
// @Message(id = 12, value = "Protocol with relative path %s is already defined.")
// OperationFailedException protocolAlreadyDefined(String relativePath);
// @Message(id = 13, value = "Protocol with relative path %s is not defined.")
// OperationFailedException protocolNotDefined(String relativePath);
// @Message(id = 14, value = "Property %s for protocol with relative path %s is not defined.")
// OperationFailedException propertyNotDefined(String propertyName, String protocolRelativePath);
@Message(id = 15, value = "Unknown metric %s")
String unknownMetric(String metricName);
@Message(id = 16, value = "Unable to load protocol class %s")
OperationFailedException unableToLoadProtocolClass(String protocolName);
// @Message(id = 17, value = "Privileged access exception on attribute/method %s")
// String privilegedAccessExceptionForAttribute(String attrName);
// @Message(id = 18, value = "Instantiation exception on converter for attribute/method %s")
// String instantiationExceptionOnConverterForAttribute(String attrName);
// @Message(id = 20, value = "Unable to load protocol class %s")
// String unableToLoadProtocol(String protocolName);
// @Message(id = 21, value = "Attributes referencing threads subsystem can only be used to support older secondary hosts in the domain.")
// String threadsAttributesUsedInRuntime();
@Message(id = 22, value = "%s entry not found in configured key store")
IllegalArgumentException keyEntryNotFound(String alias);
@Message(id = 23, value = "%s key store entry is not of the expected type: %s")
IllegalArgumentException unexpectedKeyStoreEntryType(String alias, String type);
// @Message(id = 24, value = "%s key store entry does not contain a secret key")
// IllegalArgumentException secretKeyStoreEntryExpected(String alias);
@Message(id = 25, value = "Configured credential source does not reference a clear-text password credential")
IllegalArgumentException unexpectedCredentialSource();
// @Message(id = 26, value = "No %s operation registered at %s")
// OperationFailedException operationNotDefined(String operation, String address);
// @Message(id = 27, value = "Failed to synthesize key-store add operation due to missing %s property")
// OperationFailedException missingKeyStoreProperty(String propertyName);
@Message(id = 28, value = "Could not resolve destination address for outbound socket binding named '%s'")
IllegalArgumentException failedToResolveSocketBinding(@Cause UnknownHostException cause, OutboundSocketBinding binding);
// @LogMessage(level = WARN)
// @Message(id = 29, value = "Ignoring unrecognized %s properties: %s")
// void ignoredProperties(String protocol, Map<String, String> properties);
@LogMessage(level = WARN)
@Message(id = 30, value = "Protocol %s is obsolete and will be auto-updated to %s")
void legacyProtocol(String legacyProtocol, String targetProtocol);
@LogMessage(level = WARN)
@Message(id = 31, value = "Ignoring unrecognized %s property: %s")
void unrecognizedProtocolProperty(String protocol, String property);
@LogMessage(level = INFO)
@Message(id = 32, value = "Connecting '%s' channel. '%s' joining cluster '%s' via %s")
void connecting(String channelName, String nodeName, String clusterName, InetSocketAddress address);
@LogMessage(level = INFO)
@Message(id = 33, value = "Connected '%s' channel. '%s' joined cluster '%s' with view: %s")
void connected(String channelName, String nodeName, String clusterName, View view);
@LogMessage(level = INFO)
@Message(id = 34, value = "Disconnecting '%s' channel. '%s' leaving cluster '%s' with view: %s")
void disconnecting(String channelName, String nodeName, String clusterName, View view);
@LogMessage(level = INFO)
@Message(id = 35, value = "Disconnected '%s' channel. '%s' left cluster '%s'")
void disconnected(String channelName, String nodeName, String clusterName);
}
| 9,026
| 47.532258
| 223
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/LegacyProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.dmr.ModelNode;
/**
* Resource definition for legacy protocols.
* @author Paul Ferraro
*/
public class LegacyProtocolResourceDefinition extends ProtocolResourceDefinition {
private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<OperationStepHandler> operationTransformation;
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(String targetName, UnaryOperator<ResourceDescriptor> configurator) {
this.operationTransformation = new OperationTransformation(targetName);
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor).setAddOperationTransformation(this.operationTransformation).setOperationTransformation(this.operationTransformation);
}
}
private static class OperationTransformation implements UnaryOperator<OperationStepHandler>, OperationStepHandler {
private final String targetName;
OperationTransformation(String targetName) {
this.targetName = targetName;
}
@Override
public OperationStepHandler apply(OperationStepHandler handler) {
return this;
}
@Override
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress();
JGroupsLogger.ROOT_LOGGER.legacyProtocol(address.getLastElement().getValue(), this.targetName);
PathAddress targetAddress = address.getParent().append(pathElement(this.targetName));
operation.get(ModelDescriptionConstants.OP_ADDR).set(targetAddress.toModelNode());
PathAddress targetRegistrationAddress = address.getParent().append(ProtocolResourceDefinition.WILDCARD_PATH);
String operationName = operation.get(ModelDescriptionConstants.OP).asString();
context.addStep(operation, context.getRootResourceRegistration().getOperationHandler(targetRegistrationAddress, operationName), OperationContext.Stage.MODEL, true);
}
}
LegacyProtocolResourceDefinition(String name, String targetName, JGroupsSubsystemModel deprecation, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(pathElement(name), new ResourceDescriptorConfigurator(targetName, configurator), null, parentServiceConfiguratorFactory);
this.setDeprecated(deprecation.getVersion());
}
}
| 4,201
| 47.860465
| 222
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/SocketDiscoveryProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.net.InetSocketAddress;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.StringListAttributeDefinition;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.registry.AttributeAccess;
/**
* @author Paul Ferraro
*/
public class SocketDiscoveryProtocolResourceDefinition<A> extends ProtocolResourceDefinition {
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<StringListAttributeDefinition.Builder> {
OUTBOUND_SOCKET_BINDINGS("socket-bindings") {
@Override
public StringListAttributeDefinition.Builder apply(StringListAttributeDefinition.Builder builder) {
return builder.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.setCapabilityReference(new CapabilityReference(Capability.PROTOCOL, CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING))
;
}
},
;
private final AttributeDefinition definition;
Attribute(String name) {
this.definition = this.apply(new StringListAttributeDefinition.Builder(name)
.setRequired(true)
.setMinSize(1)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) {
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor)
.addAttributes(Attribute.class)
.setAddOperationTransformation(new LegacyAddOperationTransformation(Attribute.class))
.setOperationTransformation(LEGACY_OPERATION_TRANSFORMER)
;
}
}
private static class SocketDiscoveryProtocolConfigurationConfiguratorFactory<A> implements ResourceServiceConfiguratorFactory {
private final Function<InetSocketAddress, A> hostTransformer;
SocketDiscoveryProtocolConfigurationConfiguratorFactory(Function<InetSocketAddress, A> hostTransformer) {
this.hostTransformer = hostTransformer;
}
@Override
public ResourceServiceConfigurator createServiceConfigurator(PathAddress address) {
return new SocketDiscoveryProtocolConfigurationServiceConfigurator<>(address, this.hostTransformer);
}
}
SocketDiscoveryProtocolResourceDefinition(String name, Function<InetSocketAddress, A> hostTransformer, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(pathElement(name), new ResourceDescriptorConfigurator(configurator), new SocketDiscoveryProtocolConfigurationConfiguratorFactory<>(hostTransformer), parentServiceConfiguratorFactory);
}
}
| 4,889
| 45.571429
| 225
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AbstractProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.PropertiesAttributeDefinition;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.RestartParentResourceRegistrar;
import org.jboss.as.clustering.controller.SimpleResourceServiceHandler;
import org.jboss.as.clustering.controller.validation.ModuleIdentifierValidatorBuilder;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* Resource description for /subsystem=jgroups/stack=X/protocol=Y
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
* @author Paul Ferraro
*/
public class AbstractProtocolResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> {
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
MODULE(ModelDescriptionConstants.MODULE, ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setDefaultValue(new ModelNode("org.jgroups"))
.setValidator(new ModuleIdentifierValidatorBuilder().configure(builder).build())
;
}
},
PROPERTIES(ModelDescriptionConstants.PROPERTIES),
STATISTICS_ENABLED(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN),
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(true)
.setRequired(false)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
Attribute(String name) {
this.definition = new PropertiesAttributeDefinition.Builder(name)
.setAllowExpression(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder;
}
}
private final UnaryOperator<ResourceDescriptor> configurator;
private final ResourceServiceHandler handler;
private final ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory;
AbstractProtocolResourceDefinition(Parameters parameters, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(parameters);
this.configurator = configurator;
this.handler = new SimpleResourceServiceHandler(serviceConfiguratorFactory);
this.parentServiceConfiguratorFactory = parentServiceConfiguratorFactory;
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = this.configurator.apply(new ResourceDescriptor(this.getResourceDescriptionResolver()))
.addAttributes(Attribute.class)
;
new RestartParentResourceRegistrar(this.parentServiceConfiguratorFactory, descriptor, this.handler).register(registration);
return registration;
}
}
| 5,262
| 45.166667
| 243
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AbstractProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.AbstractProtocolResourceDefinition.Attribute.MODULE;
import static org.jboss.as.clustering.jgroups.subsystem.AbstractProtocolResourceDefinition.Attribute.PROPERTIES;
import static org.jboss.as.clustering.jgroups.subsystem.AbstractProtocolResourceDefinition.Attribute.STATISTICS_ENABLED;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.jgroups.ProtocolDefaults;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.server.Services;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoader;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.jgroups.Global;
import org.jgroups.stack.Configurator;
import org.jgroups.stack.Protocol;
import org.jgroups.util.StackType;
import org.jgroups.util.Util;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;
import org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.FunctionalService;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* @author Paul Ferraro
*/
public abstract class AbstractProtocolConfigurationServiceConfigurator<P extends Protocol, C extends ProtocolConfiguration<P>> implements ResourceServiceConfigurator, ProtocolConfiguration<P>, Consumer<P>, Supplier<C>, Dependency {
private final String name;
private final Map<String, String> properties = new HashMap<>();
private volatile Supplier<ModuleLoader> loader;
private volatile Supplier<ProtocolDefaults> defaults;
private volatile String moduleName;
private volatile Boolean statisticsEnabled;
protected AbstractProtocolConfigurationServiceConfigurator(String name) {
this.name = name;
}
@Override
public final ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<C> configuration = this.register(builder).provides(this.getServiceName());
Service service = new FunctionalService<>(configuration, Function.identity(), this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
this.loader = builder.requires(Services.JBOSS_SERVICE_MODULE_LOADER);
this.defaults = builder.requires(ProtocolDefaultsServiceConfigurator.SERVICE_NAME);
return builder;
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.moduleName = MODULE.resolveModelAttribute(context, model).asString();
this.properties.clear();
for (Property property : PROPERTIES.resolveModelAttribute(context, model).asPropertyListOrEmpty()) {
this.properties.put(property.getName(), property.getValue().asString());
}
this.statisticsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBooleanOrNull();
return this;
}
@Override
public String getName() {
return this.name;
}
@Override
public final P createProtocol(ProtocolStackConfiguration stackConfiguration) {
String protocolName = this.name;
String moduleName = this.moduleName;
// A "native" protocol is one that is not specified as a class name
boolean nativeProtocol = moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(Global.PREFIX);
String className = nativeProtocol ? (Global.PREFIX + protocolName) : protocolName;
try {
Module module = this.loader.get().loadModule(moduleName);
Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class);
Map<String, String> properties = new HashMap<>(this.defaults.get().getProperties(protocolClass));
properties.putAll(this.properties);
PrivilegedExceptionAction<Protocol> action = new PrivilegedExceptionAction<>() {
@Override
public Protocol run() throws Exception {
try {
Protocol protocol = protocolClass.getConstructor().newInstance();
// These Configurator methods are destructive, so make a defensive copy
Map<String, String> copy = new HashMap<>(properties);
StackType type = Util.getIpStackType();
Configurator.resolveAndAssignFields(protocol, copy, type);
Configurator.resolveAndInvokePropertyMethods(protocol, copy, type);
List<Object> objects = protocol.getComponents();
if (objects != null) {
for (Object object : objects) {
Configurator.resolveAndAssignFields(object, copy, type);
Configurator.resolveAndInvokePropertyMethods(object, copy, type);
}
}
if (!copy.isEmpty()) {
for (String property : copy.keySet()) {
JGroupsLogger.ROOT_LOGGER.unrecognizedProtocolProperty(protocolName, property);
}
}
return protocol;
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
};
@SuppressWarnings("unchecked")
P protocol = (P) WildFlySecurityManager.doUnchecked(action);
this.accept(protocol);
protocol.enableStats(this.statisticsEnabled != null ? this.statisticsEnabled : stackConfiguration.isStatisticsEnabled());
return protocol;
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
void setValue(P protocol, String propertyName, Object propertyValue) {
PrivilegedAction<P> action = new PrivilegedAction<>() {
@Override
public P run() {
return protocol.setValue(propertyName, propertyValue);
}
};
WildFlySecurityManager.doUnchecked(action);
}
}
| 8,241
| 46.918605
| 231
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelMetricExecutor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Function;
import org.jboss.as.clustering.controller.FunctionExecutor;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.Metric;
import org.jboss.as.clustering.controller.MetricExecutor;
import org.jboss.as.clustering.controller.MetricFunction;
import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceName;
import org.jgroups.JChannel;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
/**
* Handler for reading run-time only attributes from an underlying channel service.
*
* @author Richard Achmatowicz (c) 2013 Red Hat Inc.
* @author Paul Ferraro
*/
public class ChannelMetricExecutor implements MetricExecutor<JChannel> {
private final FunctionExecutorRegistry<JChannel> executors;
public ChannelMetricExecutor(FunctionExecutorRegistry<JChannel> executors) {
this.executors = executors;
}
@Override
public ModelNode execute(OperationContext context, Metric<JChannel> metric) throws OperationFailedException {
ServiceName name = JGroupsRequirement.CHANNEL.getServiceName(context, UnaryCapabilityNameResolver.DEFAULT);
FunctionExecutor<JChannel> executor = this.executors.get(name);
return (executor != null) ? executor.execute(new MetricFunction<>(Function.identity(), metric)) : null;
}
}
| 2,620
| 42.683333
| 115
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AuthTokenResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Consumer;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.security.CredentialReference;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for auth token resources.
* @author Paul Ferraro
*/
public class AuthTokenResourceTransformer implements Consumer<ModelVersion> {
final ResourceTransformationDescriptionBuilder builder;
AuthTokenResourceTransformer(ResourceTransformationDescriptionBuilder builder) {
this.builder = builder;
}
@Override
public void accept(ModelVersion version) {
if (JGroupsSubsystemModel.VERSION_8_0_0.requiresTransformation(version)) {
this.builder.getAttributeBuilder()
.addRejectCheck(CredentialReference.REJECT_CREDENTIAL_REFERENCE_WITH_BOTH_STORE_AND_CLEAR_TEXT, AuthTokenResourceDefinition.Attribute.SHARED_SECRET.getName())
.end();
}
}
}
| 2,068
| 38.788462
| 178
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/TransportConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.TransportResourceDefinition.Attribute.DIAGNOSTICS_SOCKET_BINDING;
import static org.jboss.as.clustering.jgroups.subsystem.TransportResourceDefinition.Attribute.MACHINE;
import static org.jboss.as.clustering.jgroups.subsystem.TransportResourceDefinition.Attribute.RACK;
import static org.jboss.as.clustering.jgroups.subsystem.TransportResourceDefinition.Attribute.SITE;
import static org.jboss.as.clustering.jgroups.subsystem.TransportResourceDefinition.Attribute.SOCKET_BINDING;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.jgroups.ClassLoaderThreadFactory;
import org.jboss.as.clustering.jgroups.JChannelFactory;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.ClientMapping;
import org.jboss.as.network.SocketBinding;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jgroups.protocols.TP;
import org.jgroups.stack.DiagnosticsHandler;
import org.jgroups.util.DefaultThreadFactory;
import org.jgroups.util.ThreadPool;
import org.wildfly.clustering.jgroups.spi.TransportConfiguration;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceNameProvider;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SimpleSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class TransportConfigurationServiceConfigurator<T extends TP> extends AbstractProtocolConfigurationServiceConfigurator<T, TransportConfiguration<T>> implements TransportConfiguration<T> {
private final ServiceNameProvider provider;
private final SupplierDependency<ThreadPoolConfiguration> threadPoolConfiguration;
private volatile SupplierDependency<SocketBinding> socketBinding;
private volatile SupplierDependency<SocketBinding> diagnosticsSocketBinding;
private volatile Topology topology = null;
public TransportConfigurationServiceConfigurator(PathAddress address) {
super(address.getLastElement().getValue());
this.provider = new SingletonProtocolServiceNameProvider(address);
this.threadPoolConfiguration = new ServiceSupplierDependency<>(new ThreadPoolServiceNameProvider(address, ThreadPoolResourceDefinition.DEFAULT.getPathElement()));
}
@Override
public ServiceName getServiceName() {
return this.provider.getServiceName();
}
@Override
public TransportConfiguration<T> get() {
return this;
}
@Override
public <B> ServiceBuilder<B> register(ServiceBuilder<B> builder) {
return super.register(new CompositeDependency(this.threadPoolConfiguration, this.socketBinding, this.diagnosticsSocketBinding).register(builder));
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.socketBinding = new ServiceSupplierDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, SOCKET_BINDING.resolveModelAttribute(context, model).asString()));
String diagnosticsSocketBinding = DIAGNOSTICS_SOCKET_BINDING.resolveModelAttribute(context, model).asStringOrNull();
this.diagnosticsSocketBinding = (diagnosticsSocketBinding != null) ? new ServiceSupplierDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, diagnosticsSocketBinding)) : new SimpleSupplierDependency<>(null);
ModelNode machine = MACHINE.resolveModelAttribute(context, model);
ModelNode rack = RACK.resolveModelAttribute(context, model);
ModelNode site = SITE.resolveModelAttribute(context, model);
if (site.isDefined() || rack.isDefined() || machine.isDefined()) {
this.topology = new Topology() {
@Override
public String getMachine() {
return machine.asStringOrNull();
}
@Override
public String getRack() {
return rack.asStringOrNull();
}
@Override
public String getSite() {
return site.asStringOrNull();
}
};
}
return super.configure(context, model);
}
@Override
public Map<String, SocketBinding> getSocketBindings() {
Map<String, SocketBinding> bindings = new TreeMap<>();
SocketBinding binding = this.getSocketBinding();
for (String serviceName : Set.of("jgroups.udp.mcast_sock", "jgroups.udp.sock", "jgroups.tcp.server", "jgroups.nio.server", "jgroups.tunnel.ucast_sock")) {
bindings.put(serviceName, binding);
}
bindings.put("jgroups.tp.diag.mcast_sock", this.diagnosticsSocketBinding.get());
return bindings;
}
@Override
public void accept(T protocol) {
SocketBinding binding = this.getSocketBinding();
InetSocketAddress socketAddress = binding.getSocketAddress();
protocol.setBindAddress(socketAddress.getAddress());
protocol.setBindPort(socketAddress.getPort());
List<ClientMapping> clientMappings = binding.getClientMappings();
if (!clientMappings.isEmpty()) {
// JGroups cannot select a client mapping based on the source address, so just use the first one
ClientMapping mapping = clientMappings.get(0);
try {
protocol.setExternalAddr(InetAddress.getByName(mapping.getDestinationAddress()));
protocol.setExternalPort(mapping.getDestinationPort());
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e);
}
}
ThreadPoolConfiguration threadPoolConfiguration = this.threadPoolConfiguration.get();
ThreadPool threadPool = protocol.getThreadPool();
threadPool.setMinThreads(threadPoolConfiguration.getMinThreads());
threadPool.setMaxThreads(threadPoolConfiguration.getMaxThreads());
threadPool.setKeepAliveTime(threadPoolConfiguration.getKeepAliveTime());
// Let JGroups retransmit if pool is full
threadPool.setRejectionPolicy("discard");
// JGroups propagates this to the ThreadPool
protocol.setThreadFactory(new ClassLoaderThreadFactory(new DefaultThreadFactory("jgroups", false, true).useVirtualThreads(protocol.useVirtualThreads()), JChannelFactory.class.getClassLoader()));
SocketBinding diagnosticsBinding = this.diagnosticsSocketBinding.get();
if (diagnosticsBinding != null) {
DiagnosticsHandler handler = new DiagnosticsHandler(protocol.getLog(), protocol.getSocketFactory(), protocol.getThreadFactory());
InetSocketAddress address = diagnosticsBinding.getSocketAddress();
handler.setBindAddress(address.getAddress());
if (diagnosticsBinding.getMulticastAddress() != null) {
handler.setMcastAddress(diagnosticsBinding.getMulticastAddress());
handler.setPort(diagnosticsBinding.getMulticastPort());
} else {
handler.setPort(diagnosticsBinding.getPort());
}
try {
protocol.setDiagnosticsHandler(handler);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
@Override
public Topology getTopology() {
return this.topology;
}
@Override
public SocketBinding getSocketBinding() {
return this.socketBinding.get();
}
}
| 9,127
| 45.571429
| 237
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/GenericProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.controller.PathElement;
import org.jgroups.Global;
/**
* @author Paul Ferraro
*/
public class GenericProtocolResourceDefinition extends ProtocolResourceDefinition {
public static PathElement pathElement(String name) {
return ProtocolResourceDefinition.pathElement(Global.PREFIX + name);
}
GenericProtocolResourceDefinition(UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
this(WILDCARD_PATH, configurator, parentServiceConfiguratorFactory);
}
GenericProtocolResourceDefinition(String name, JGroupsSubsystemModel deprecation, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
this(pathElement(name), configurator, parentServiceConfiguratorFactory);
this.setDeprecated(deprecation.getVersion());
}
private GenericProtocolResourceDefinition(PathElement path, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(path, configurator, ProtocolConfigurationServiceConfigurator::new, parentServiceConfiguratorFactory);
}
}
| 2,483
| 45
| 204
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JDBCProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE;
import javax.sql.DataSource;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jgroups.protocols.JDBC_PING;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class JDBCProtocolConfigurationServiceConfigurator extends ProtocolConfigurationServiceConfigurator<JDBC_PING> {
private volatile SupplierDependency<DataSource> dataSource;
public JDBCProtocolConfigurationServiceConfigurator(PathAddress address) {
super(address);
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
return super.register(this.dataSource.register(builder));
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.dataSource = new ServiceSupplierDependency<>(CommonUnaryRequirement.DATA_SOURCE.getServiceName(context, DATA_SOURCE.resolveModelAttribute(context, model).asString()));
return super.configure(context, model);
}
@Override
public void accept(JDBC_PING protocol) {
protocol.setDataSource(this.dataSource.get());
}
}
| 2,709
| 39.447761
| 180
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/SocketTransportConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.SocketTransportResourceDefinition.Attribute.*;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Set;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.SocketBinding;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jgroups.protocols.BasicTCP;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SimpleSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class SocketTransportConfigurationServiceConfigurator<TP extends BasicTCP> extends TransportConfigurationServiceConfigurator<TP> {
private volatile SupplierDependency<SocketBinding> clientBinding;
public SocketTransportConfigurationServiceConfigurator(PathAddress address) {
super(address);
}
@Override
public <B> ServiceBuilder<B> register(ServiceBuilder<B> builder) {
return super.register(this.clientBinding.register(builder));
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
String bindingName = CLIENT_SOCKET_BINDING.resolveModelAttribute(context, model).asStringOrNull();
this.clientBinding = (bindingName != null) ? new ServiceSupplierDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, bindingName)) : new SimpleSupplierDependency<>(null);
return super.configure(context, model);
}
@Override
public Map<String, SocketBinding> getSocketBindings() {
Map<String, SocketBinding> bindings = super.getSocketBindings();
SocketBinding clientBinding = this.clientBinding.get();
for (String serviceName : Set.of("jgroups.tcp.sock", "jgroups.nio.client")) {
bindings.put(serviceName, clientBinding);
}
return bindings;
}
@Override
public void accept(TP protocol) {
SocketBinding clientBinding = this.clientBinding.get();
if (clientBinding != null) {
InetSocketAddress socketAddress = clientBinding.getSocketAddress();
this.setValue(protocol, "client_bind_addr", socketAddress.getAddress());
this.setValue(protocol, "client_bind_port", socketAddress.getPort());
}
super.accept(protocol);
}
}
| 3,736
| 41.465909
| 200
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/XMLElement.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
public enum XMLElement {
// must be first
UNKNOWN(""),
AUTH_PROTOCOL("auth-protocol"),
CIPHER_TOKEN("cipher-token"),
CHANNEL(ChannelResourceDefinition.WILDCARD_PATH),
CHANNELS("channels"),
DEFAULT_THREAD_POOL("default-thread-pool"),
DIGEST_TOKEN("digest-token"),
ENCRYPT_PROTOCOL("encrypt-protocol"),
FORK(ForkResourceDefinition.WILDCARD_PATH),
INTERNAL_THREAD_POOL("internal-thread-pool"),
JDBC_PROTOCOL("jdbc-protocol"),
KEY_CREDENTIAL_REFERENCE(EncryptProtocolResourceDefinition.Attribute.KEY_CREDENTIAL),
OOB_THREAD_POOL("oob-thread-pool"),
PLAIN_TOKEN("plain-token"),
PROPERTY(ModelDescriptionConstants.PROPERTY),
PROTOCOL(ProtocolResourceDefinition.WILDCARD_PATH),
RELAY(RelayResourceDefinition.WILDCARD_PATH),
REMOTE_SITE(RemoteSiteResourceDefinition.WILDCARD_PATH),
SHARED_SECRET_CREDENTIAL_REFERENCE(AuthTokenResourceDefinition.Attribute.SHARED_SECRET),
SOCKET_PROTOCOL("socket-protocol"),
SOCKET_DISCOVERY_PROTOCOL("socket-discovery-protocol"),
STACK(StackResourceDefinition.WILDCARD_PATH),
STACKS("stacks"),
TIMER_THREAD_POOL("timer-thread-pool"),
TRANSPORT(TransportResourceDefinition.WILDCARD_PATH),
;
private final String name;
XMLElement(PathElement path) {
this.name = path.isWildcard() ? path.getKey() : path.getValue();
}
XMLElement(Attribute attribute) {
this.name = attribute.getName();
}
XMLElement(String name) {
this.name = name;
}
/**
* Get the local name of this element.
*
* @return the local name
*/
public String getLocalName() {
return this.name;
}
@Override
public String toString() {
return this.name;
}
private enum XMLElementFunction implements Function<ModelNode, XMLElement> {
PROTOCOL(XMLElement.PROTOCOL),
SOCKET_PROTOCOL(XMLElement.SOCKET_PROTOCOL),
JDBC_PROTOCOL(XMLElement.JDBC_PROTOCOL),
ENCRYPT_PROTOCOL(XMLElement.ENCRYPT_PROTOCOL),
SOCKET_DISCOVERY_PROTOCOL(XMLElement.SOCKET_DISCOVERY_PROTOCOL),
AUTH_PROTOCOL(XMLElement.AUTH_PROTOCOL),
;
private final XMLElement element;
XMLElementFunction(XMLElement element) {
this.element = element;
}
@Override
public XMLElement apply(ModelNode ignored) {
return this.element;
}
}
private static final Map<String, XMLElement> elements = new HashMap<>();
private static final Map<String, Function<ModelNode, XMLElement>> protocols = new HashMap<>();
private static final Map<String, XMLElement> tokens = new HashMap<>();
static {
for (XMLElement element : values()) {
String name = element.getLocalName();
if (name != null) {
elements.put(name, element);
}
}
Function<ModelNode, XMLElement> function = new Function<>() {
@Override
public XMLElement apply(ModelNode model) {
// Use socket-protocol element only if optional socket-binding was defined
return model.hasDefined(SocketProtocolResourceDefinition.Attribute.SOCKET_BINDING.getName()) ? XMLElement.SOCKET_PROTOCOL : XMLElement.PROTOCOL;
}
};
for (ProtocolResourceRegistrar.SocketProtocol protocol : EnumSet.allOf(ProtocolResourceRegistrar.SocketProtocol.class)) {
protocols.put(protocol.name(), function);
}
for (ProtocolResourceRegistrar.MulticastProtocol protocol : EnumSet.allOf(ProtocolResourceRegistrar.MulticastProtocol.class)) {
protocols.put(protocol.name(), XMLElementFunction.SOCKET_PROTOCOL);
}
for (ProtocolResourceRegistrar.JdbcProtocol protocol : EnumSet.allOf(ProtocolResourceRegistrar.JdbcProtocol.class)) {
protocols.put(protocol.name(), XMLElementFunction.JDBC_PROTOCOL);
}
for (ProtocolResourceRegistrar.EncryptProtocol protocol : EnumSet.allOf(ProtocolResourceRegistrar.EncryptProtocol.class)) {
protocols.put(protocol.name(), XMLElementFunction.ENCRYPT_PROTOCOL);
}
for (ProtocolResourceRegistrar.InitialHostsProtocol protocol : EnumSet.allOf(ProtocolResourceRegistrar.InitialHostsProtocol.class)) {
protocols.put(protocol.name(), XMLElementFunction.SOCKET_DISCOVERY_PROTOCOL);
}
for (ProtocolResourceRegistrar.AuthProtocol protocol : EnumSet.allOf(ProtocolResourceRegistrar.AuthProtocol.class)) {
protocols.put(protocol.name(), XMLElementFunction.AUTH_PROTOCOL);
}
tokens.put(PlainAuthTokenResourceDefinition.PATH.getValue(), XMLElement.PLAIN_TOKEN);
tokens.put(DigestAuthTokenResourceDefinition.PATH.getValue(), XMLElement.DIGEST_TOKEN);
tokens.put(CipherAuthTokenResourceDefinition.PATH.getValue(), XMLElement.CIPHER_TOKEN);
}
public static XMLElement forName(String localName) {
return elements.getOrDefault(localName, UNKNOWN);
}
public static XMLElement forProtocolName(Property protocol) {
return protocols.getOrDefault(protocol.getName(), XMLElementFunction.PROTOCOL).apply(protocol.getValue());
}
public static XMLElement forAuthTokenName(String token) {
XMLElement element = tokens.get(token);
if (element == null) throw new IllegalArgumentException(token);
return element;
}
}
| 6,946
| 39.156069
| 160
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.msc.service.ServiceName;
import org.jgroups.stack.Protocol;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;
import org.wildfly.clustering.service.ServiceNameProvider;
/**
* @author Paul Ferraro
*/
public class ProtocolConfigurationServiceConfigurator<P extends Protocol> extends AbstractProtocolConfigurationServiceConfigurator<P, ProtocolConfiguration<P>> {
private final ServiceNameProvider provider;
public ProtocolConfigurationServiceConfigurator(PathAddress address) {
super(address.getLastElement().getValue());
this.provider = new ProtocolServiceNameProvider(address);
}
@Override
public ServiceName getServiceName() {
return this.provider.getServiceName();
}
@Override
public ProtocolConfiguration<P> get() {
return this;
}
@Override
public void accept(P protocol) {
}
}
| 2,021
| 34.473684
| 161
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AuthProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.ResourceCapabilityReference;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver;
import org.jboss.as.clustering.jgroups.auth.BinaryAuthToken;
import org.jboss.as.clustering.jgroups.auth.CipherAuthToken;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jgroups.conf.ClassConfigurator;
/**
* @author Paul Ferraro
*/
public class AuthProtocolResourceDefinition extends ProtocolResourceDefinition {
static {
ClassConfigurator.add((short) 1100, BinaryAuthToken.class);
ClassConfigurator.add((short) 1101, CipherAuthToken.class);
}
private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) {
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor)
.setAddOperationTransformation(new LegacyAddOperationTransformation("auth_class"))
.setOperationTransformation(LEGACY_OPERATION_TRANSFORMER)
.addResourceCapabilityReference(new ResourceCapabilityReference(Capability.PROTOCOL, AuthTokenResourceDefinition.Capability.AUTH_TOKEN, UnaryCapabilityNameResolver.PARENT))
;
}
}
AuthProtocolResourceDefinition(String name, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(pathElement(name), new ResourceDescriptorConfigurator(configurator), AuthProtocolConfigurationServiceConfigurator::new, parentServiceConfiguratorFactory);
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = super.register(parent);
new PlainAuthTokenResourceDefinition().register(registration);
new DigestAuthTokenResourceDefinition().register(registration);
new CipherAuthTokenResourceDefinition().register(registration);
return registration;
}
}
| 3,568
| 44.75641
| 192
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.BinaryCapabilityNameResolver;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
/**
* @author Paul Ferraro
*/
public class ProtocolResourceDefinition extends AbstractProtocolResourceDefinition {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
public static PathElement pathElement(String name) {
return PathElement.pathElement("protocol", name);
}
enum Capability implements org.jboss.as.clustering.controller.Capability {
PROTOCOL("org.wildfly.clustering.jgroups.protocol"),
;
private final RuntimeCapability<Void> definition;
Capability(String name) {
this.definition = RuntimeCapability.Builder.of(name, true).setDynamicNameMapper(BinaryCapabilityNameResolver.PARENT_CHILD).setAllowMultipleRegistrations(true).build();
}
@Override
public RuntimeCapability<?> getDefinition() {
return this.definition;
}
}
static final UnaryOperator<OperationStepHandler> LEGACY_OPERATION_TRANSFORMER = new UnaryOperator<>() {
@Override
public OperationStepHandler apply(OperationStepHandler handler) {
return new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
PathAddress parentAddress = address.getParent();
Resource parent = context.readResourceFromRoot(parentAddress, false);
PathElement legacyPath = GenericProtocolResourceDefinition.pathElement(address.getLastElement().getValue());
// If legacy protocol exists, transform this operation using the legacy protocol as the target resource
if (parent.hasChild(legacyPath)) {
PathAddress legacyAddress = parentAddress.append(legacyPath);
operation.get(ModelDescriptionConstants.OP_ADDR).set(legacyAddress.toModelNode());
String operationName = operation.get(ModelDescriptionConstants.OP).asString();
context.addStep(operation, context.getRootResourceRegistration().getOperationHandler(legacyAddress, operationName), OperationContext.Stage.MODEL);
} else {
handler.execute(context, operation);
}
}
};
}
};
static class LegacyAddOperationTransformation implements UnaryOperator<OperationStepHandler> {
private final Predicate<ModelNode> legacy;
<E extends Enum<E> & org.jboss.as.clustering.controller.Attribute> LegacyAddOperationTransformation(Class<E> attributeClass) {
// If none of the specified attributes are defined, then this is a legacy operation
this.legacy = operation -> {
for (org.jboss.as.clustering.controller.Attribute attribute : EnumSet.allOf(attributeClass)) {
if (operation.hasDefined(attribute.getName())) return false;
}
return true;
};
}
LegacyAddOperationTransformation(String... legacyProperties) {
// If any of the specified properties are defined, then this is a legacy operation
this.legacy = operation -> {
if (!operation.hasDefined(Attribute.PROPERTIES.getName())) return false;
for (String legacyProperty : legacyProperties) {
if (operation.get(Attribute.PROPERTIES.getName()).hasDefined(legacyProperty)) return true;
}
return false;
};
}
@Override
public OperationStepHandler apply(OperationStepHandler handler) {
return (context, operation) -> {
if (this.legacy.test(operation)) {
PathElement path = context.getCurrentAddress().getLastElement();
// This is a legacy add operation - process it using the generic handler
OperationStepHandler genericHandler = context.getResourceRegistration().getParent().getOperationHandler(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
operation.get(ModelDescriptionConstants.OP_ADDR).set(context.getCurrentAddress().getParent().append(GenericProtocolResourceDefinition.pathElement(path.getValue())).toModelNode());
// Process this step first to preserve protocol order
context.addStep(operation, genericHandler, OperationContext.Stage.MODEL, true);
} else {
handler.execute(context, operation);
}
};
}
}
private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) {
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor).addCapabilities(Capability.class);
}
}
ProtocolResourceDefinition(PathElement path, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(new Parameters(path, path.isWildcard() ? JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(path) : JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(path, WILDCARD_PATH)).setOrderedChild(), new ResourceDescriptorConfigurator(configurator), serviceConfiguratorFactory, parentServiceConfiguratorFactory);
}
}
| 7,715
| 50.44
| 328
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Consumer;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for channel resources.
* @author Paul Ferraro
*/
public class ChannelResourceTransformer implements Consumer<ModelVersion> {
private final ResourceTransformationDescriptionBuilder builder;
ChannelResourceTransformer(ResourceTransformationDescriptionBuilder parent) {
this.builder = parent.addChildResource(ChannelResourceDefinition.WILDCARD_PATH);
}
@Override
public void accept(ModelVersion version) {
new ForkResourceTransformer(this.builder).accept(version);
}
}
| 1,784
| 36.978723
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/RemoteSiteServiceNameProvider.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.service.ServiceNameProvider;
/**
* @author Paul Ferraro
*/
public class RemoteSiteServiceNameProvider implements ServiceNameProvider {
private final ServiceName name;
public RemoteSiteServiceNameProvider(PathAddress address) {
this(address.getParent(), address.getLastElement());
}
public RemoteSiteServiceNameProvider(PathAddress relayAddress, PathElement path) {
this.name = new SingletonProtocolServiceNameProvider(relayAddress).getServiceName().append(path.getValue());
}
@Override
public ServiceName getServiceName() {
return this.name;
}
}
| 1,845
| 35.92
| 116
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/CipherAuthTokenServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.CipherAuthTokenResourceDefinition.Attribute.ALGORITHM;
import static org.jboss.as.clustering.jgroups.subsystem.CipherAuthTokenResourceDefinition.Attribute.KEY_ALIAS;
import static org.jboss.as.clustering.jgroups.subsystem.CipherAuthTokenResourceDefinition.Attribute.KEY_CREDENTIAL;
import static org.jboss.as.clustering.jgroups.subsystem.CipherAuthTokenResourceDefinition.Attribute.KEY_STORE;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyStore;
import javax.crypto.Cipher;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.CredentialSourceDependency;
import org.jboss.as.clustering.jgroups.auth.CipherAuthToken;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
import org.wildfly.security.credential.PasswordCredential;
import org.wildfly.security.credential.source.CredentialSource;
import org.wildfly.security.password.interfaces.ClearPassword;
/**
* @author Paul Ferraro
*/
public class CipherAuthTokenServiceConfigurator extends AuthTokenServiceConfigurator<CipherAuthToken> {
private volatile SupplierDependency<KeyStore> keyStore;
private volatile SupplierDependency<CredentialSource> keyCredentialSource;
private volatile String keyAlias;
private volatile String transformation;
public CipherAuthTokenServiceConfigurator(PathAddress address) {
super(address);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
String keyStore = KEY_STORE.resolveModelAttribute(context, model).asString();
this.keyStore = new ServiceSupplierDependency<>(CommonUnaryRequirement.KEY_STORE.getServiceName(context, keyStore));
this.keyAlias = KEY_ALIAS.resolveModelAttribute(context, model).asString();
this.keyCredentialSource = new CredentialSourceDependency(context, KEY_CREDENTIAL, model);
this.transformation = ALGORITHM.resolveModelAttribute(context, model).asString();
return super.configure(context, model);
}
@Override
public <V> ServiceBuilder<V> register(ServiceBuilder<V> builder) {
return super.register(new CompositeDependency(this.keyStore, this.keyCredentialSource).register(builder));
}
@Override
public CipherAuthToken apply(String authValue) {
KeyStore store = this.keyStore.get();
String alias = this.keyAlias;
try {
if (!store.containsAlias(alias)) {
throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias);
}
if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, KeyStore.PrivateKeyEntry.class.getSimpleName());
}
PasswordCredential credential = this.keyCredentialSource.get().getCredential(PasswordCredential.class);
if (credential == null) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
}
ClearPassword password = credential.getPassword(ClearPassword.class);
if (password == null) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
}
KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
KeyPair pair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
Cipher cipher = Cipher.getInstance(this.transformation);
return new CipherAuthToken(cipher, pair, authValue.getBytes(StandardCharsets.UTF_8));
} catch (GeneralSecurityException | IOException e) {
throw new IllegalArgumentException(e);
}
}
}
| 5,518
| 48.276786
| 151
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/RemoteSiteResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.BinaryCapabilityNameResolver;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.RestartParentResourceRegistrar;
import org.jboss.as.clustering.controller.SimpleResourceServiceHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelType;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
/**
* Resource definition for subsystem=jgroups/stack=X/relay=RELAY/remote-site=Y
*
* @author Paul Ferraro
*/
public class RemoteSiteResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
static PathElement pathElement(String name) {
return PathElement.pathElement("remote-site", name);
}
enum Capability implements org.jboss.as.clustering.controller.Capability {
REMOTE_SITE("org.wildfly.clustering.jgroups.remote-site"),
;
private final RuntimeCapability<Void> definition;
Capability(String name) {
this.definition = RuntimeCapability.Builder.of(name, true).setDynamicNameMapper(BinaryCapabilityNameResolver.GRANDPARENT_CHILD).build();
}
@Override
public RuntimeCapability<Void> getDefinition() {
return this.definition;
}
}
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
CHANNEL("channel", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setCapabilityReference(new CapabilityReference(Capability.REMOTE_SITE, JGroupsRequirement.CHANNEL_SOURCE));
}
},
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setRequired(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
private final ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory;
RemoteSiteResourceDefinition(ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(WILDCARD_PATH, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH));
this.parentServiceConfiguratorFactory = parentServiceConfiguratorFactory;
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver())
.addAttributes(Attribute.class)
.addCapabilities(Capability.class)
;
ResourceServiceHandler handler = new SimpleResourceServiceHandler(RemoteSiteConfigurationServiceConfigurator::new);
new RestartParentResourceRegistrar(this.parentServiceConfiguratorFactory, descriptor, handler).register(registration);
return registration;
}
}
| 5,114
| 43.094828
| 148
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/StackResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Consumer;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for protocol stack resources.
* @author Paul Ferraro
*/
public class StackResourceTransformer implements Consumer<ModelVersion> {
private final ResourceTransformationDescriptionBuilder builder;
StackResourceTransformer(ResourceTransformationDescriptionBuilder parent) {
this.builder = parent.addChildResource(StackResourceDefinition.WILDCARD_PATH);
}
@Override
public void accept(ModelVersion version) {
new ProtocolTransformer(this.builder).accept(version);
}
}
| 1,781
| 36.914894
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AuthTokenResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.SimpleResourceRegistrar;
import org.jboss.as.clustering.controller.SimpleResourceServiceHandler;
import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.security.CredentialReference;
import org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler;
import org.jgroups.auth.AuthToken;
import org.wildfly.clustering.service.UnaryRequirement;
/**
* @author Paul Ferraro
*/
public class AuthTokenResourceDefinition<T extends AuthToken> extends ChildResourceDefinition<ManagementResourceRegistration> {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
static PathElement pathElement(String value) {
return PathElement.pathElement("token", value);
}
enum Capability implements org.jboss.as.clustering.controller.Capability, UnaryRequirement {
AUTH_TOKEN("org.wildfly.clustering.jgroups.auth-token", AuthToken.class),
;
private final RuntimeCapability<Void> definition;
Capability(String name, Class<?> type) {
this.definition = RuntimeCapability.Builder.of(name, true).setServiceType(type).setAllowMultipleRegistrations(true).setDynamicNameMapper(UnaryCapabilityNameResolver.GRANDPARENT).build();
}
@Override
public RuntimeCapability<?> getDefinition() {
return this.definition;
}
}
enum Attribute implements org.jboss.as.clustering.controller.Attribute {
SHARED_SECRET(CredentialReference.getAttributeBuilder("shared-secret-reference", null, false, new CapabilityReference(Capability.AUTH_TOKEN, CommonUnaryRequirement.CREDENTIAL_STORE)).build()),
;
private final AttributeDefinition definition;
Attribute(AttributeDefinition definition) {
this.definition = definition;
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
protected final UnaryOperator<ResourceDescriptor> configurator;
protected final ResourceServiceConfiguratorFactory serviceConfiguratorFactory;
AuthTokenResourceDefinition(PathElement path, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory serviceConfiguratorFactory) {
super(path, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(path, WILDCARD_PATH));
this.configurator = configurator;
this.serviceConfiguratorFactory = serviceConfiguratorFactory;
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = this.configurator.apply(new ResourceDescriptor(this.getResourceDescriptionResolver()))
.addAttribute(Attribute.SHARED_SECRET, new CredentialReferenceWriteAttributeHandler(Attribute.SHARED_SECRET.getDefinition()))
.addCapabilities(Capability.class)
;
new SimpleResourceRegistrar(descriptor, new SimpleResourceServiceHandler(this.serviceConfiguratorFactory)).register(registration);
return registration;
}
}
| 4,931
| 46.423077
| 200
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/FailureDetectionProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.ClientMapping;
import org.jboss.as.network.SocketBinding;
import org.jgroups.protocols.FD_SOCK2;
/**
* @author Paul Ferraro
*/
public class FailureDetectionProtocolConfigurationServiceConfigurator extends SocketProtocolConfigurationServiceConfigurator<FD_SOCK2> {
public FailureDetectionProtocolConfigurationServiceConfigurator(PathAddress address) {
super(address);
}
@Override
public Map<String, SocketBinding> getSocketBindings() {
// Socket binding is optional
SocketBinding binding = this.getSocketBinding();
return (binding != null) ? Map.of("jgroups.nio.server.fd_sock", binding) : Map.of();
}
@Override
public void accept(FD_SOCK2 protocol) {
SocketBinding protocolBinding = this.getSocketBinding();
SocketBinding transportBinding = this.getTransport().getSocketBinding();
InetSocketAddress protocolBindAddress = (protocolBinding != null) ? protocolBinding.getSocketAddress() : null;
InetSocketAddress transportBindAddress = transportBinding.getSocketAddress();
protocol.setBindAddress(((protocolBindAddress != null) ? protocolBindAddress : transportBindAddress).getAddress());
if (protocolBinding != null) {
protocol.setOffset(protocolBindAddress.getPort() - transportBindAddress.getPort());
List<ClientMapping> clientMappings = protocolBinding.getClientMappings();
if (!clientMappings.isEmpty()) {
// JGroups cannot select a client mapping based on the source address, so just use the first one
ClientMapping mapping = clientMappings.get(0);
try {
protocol.setExternalAddress(InetAddress.getByName(mapping.getDestinationAddress()));
protocol.setExternalPort(mapping.getDestinationPort());
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e);
}
}
}
SocketBinding clientBinding = this.getClientSocketBinding();
if (clientBinding != null) {
protocol.setClientBindPort(clientBinding.getSocketAddress().getPort());
}
}
}
| 3,497
| 41.144578
| 136
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ForkResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import java.util.stream.Collectors;
import org.jboss.as.clustering.controller.CapabilityProvider;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.SimpleResourceRegistrar;
import org.jboss.as.clustering.controller.UnaryRequirementCapability;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jgroups.JChannel;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.clustering.server.service.ClusteringRequirement;
import org.wildfly.clustering.service.UnaryRequirement;
/**
* Definition of a fork resource.
* @author Paul Ferraro
*/
public class ForkResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> {
public static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
public static PathElement pathElement(String name) {
return PathElement.pathElement("fork", name);
}
enum Capability implements CapabilityProvider {
FORK_CHANNEL(JGroupsRequirement.CHANNEL),
FORK_CHANNEL_CLUSTER(JGroupsRequirement.CHANNEL_CLUSTER),
FORK_CHANNEL_FACTORY(JGroupsRequirement.CHANNEL_FACTORY),
FORK_CHANNEL_MODULE(JGroupsRequirement.CHANNEL_MODULE),
FORK_CHANNEL_SOURCE(JGroupsRequirement.CHANNEL_SOURCE),
;
private final org.jboss.as.clustering.controller.Capability capability;
Capability(UnaryRequirement requirement) {
this.capability = new UnaryRequirementCapability(requirement);
}
@Override
public org.jboss.as.clustering.controller.Capability getCapability() {
return this.capability;
}
}
static class ForkChannelFactoryServiceConfiguratorFactory implements ResourceServiceConfiguratorFactory {
@Override
public ResourceServiceConfigurator createServiceConfigurator(PathAddress address) {
return new ForkChannelFactoryServiceConfigurator(Capability.FORK_CHANNEL_FACTORY, address);
}
}
private final FunctionExecutorRegistry<JChannel> executors;
ForkResourceDefinition(FunctionExecutorRegistry<JChannel> executors) {
super(WILDCARD_PATH, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH));
this.executors = executors;
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver())
.addCapabilities(Capability.class)
.addCapabilities(EnumSet.allOf(ClusteringRequirement.class).stream().map(UnaryRequirementCapability::new).collect(Collectors.toList()))
;
ResourceServiceConfiguratorFactory serviceConfiguratorFactory = new ForkChannelFactoryServiceConfiguratorFactory();
ResourceServiceHandler handler = new ForkServiceHandler(serviceConfiguratorFactory);
new SimpleResourceRegistrar(descriptor, handler).register(registration);
new ProtocolResourceRegistrar(serviceConfiguratorFactory, new ForkProtocolRuntimeResourceRegistration(this.executors)).register(registration);
return registration;
}
}
| 4,876
| 44.579439
| 151
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/TransportResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelType;
/**
* Resource description for /subsystem=jgroups/stack=X/transport=*
*
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
* @author Paul Ferraro
*/
public class TransportResourceDefinition extends AbstractProtocolResourceDefinition {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
public static PathElement pathElement(String name) {
return PathElement.pathElement("transport", name);
}
enum Capability implements org.jboss.as.clustering.controller.Capability {
TRANSPORT("org.wildfly.clustering.jgroups.transport"),
;
private final RuntimeCapability<Void> definition;
Capability(String name) {
this.definition = RuntimeCapability.Builder.of(name, true).setDynamicNameMapper(UnaryCapabilityNameResolver.PARENT).build();
}
@Override
public RuntimeCapability<Void> getDefinition() {
return this.definition;
}
}
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
SOCKET_BINDING("socket-binding", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setAllowExpression(false)
.setRequired(true)
.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.setCapabilityReference(new CapabilityReference(Capability.TRANSPORT, CommonUnaryRequirement.SOCKET_BINDING));
}
},
DIAGNOSTICS_SOCKET_BINDING("diagnostics-socket-binding", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setAllowExpression(false)
.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.setCapabilityReference(new CapabilityReference(Capability.TRANSPORT, CommonUnaryRequirement.SOCKET_BINDING));
}
},
SITE("site", ModelType.STRING),
RACK("rack", ModelType.STRING),
MACHINE("machine", ModelType.STRING),
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(true)
.setRequired(false)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder;
}
}
static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) {
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor)
.addAttributes(Attribute.class)
.addCapabilities(Capability.class)
.addRequiredChildren(ThreadPoolResourceDefinition.class)
;
}
}
TransportResourceDefinition(ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
this(new Parameters(WILDCARD_PATH, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH, ProtocolResourceDefinition.WILDCARD_PATH)), UnaryOperator.identity(), TransportConfigurationServiceConfigurator::new, parentServiceConfiguratorFactory);
}
TransportResourceDefinition(String name, ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
this(pathElement(name), UnaryOperator.identity(), serviceConfiguratorFactory, parentServiceConfiguratorFactory);
}
TransportResourceDefinition(PathElement path, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
this(new Parameters(path, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(path, WILDCARD_PATH, ProtocolResourceDefinition.WILDCARD_PATH)), configurator, serviceConfiguratorFactory, parentServiceConfiguratorFactory);
}
private TransportResourceDefinition(Parameters parameters, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(parameters, new ResourceDescriptorConfigurator(configurator), serviceConfiguratorFactory, parentServiceConfiguratorFactory);
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = super.register(parent);
if (registration.getPathAddress().getLastElement().isWildcard()) {
for (ThreadPoolResourceDefinition pool : EnumSet.allOf(ThreadPoolResourceDefinition.class)) {
pool.register(registration);
}
}
return registration;
}
}
| 7,661
| 46.8875
| 266
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelRuntimeResourceRegistration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.AbstractProtocolResourceDefinition.Attribute.MODULE;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Attribute.STACK;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.RuntimeResourceRegistration;
import org.jboss.as.clustering.controller.descriptions.SimpleResourceDescriptionResolver;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.Attribute;
import org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.FieldType;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.ResourceBuilder;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.OverrideDescriptionProvider;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.PlaceholderResource;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoadException;
import org.jgroups.Global;
import org.jgroups.JChannel;
import org.jgroups.protocols.relay.RELAY2;
import org.jgroups.stack.Protocol;
import org.wildfly.clustering.jgroups.spi.RelayConfiguration;
/**
* @author Paul Ferraro
*/
public class ChannelRuntimeResourceRegistration implements RuntimeResourceRegistration {
private final FunctionExecutorRegistry<JChannel> executors;
public ChannelRuntimeResourceRegistration(FunctionExecutorRegistry<JChannel> executors) {
this.executors = executors;
}
@Override
public void register(OperationContext context) throws OperationFailedException {
OverrideDescriptionProvider provider = new OverrideDescriptionProvider() {
@Override
public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
return Collections.emptyMap();
}
@Override
public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
String description = JGroupsExtension.SUBSYSTEM_RESOLVER.getChildTypeDescription(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), locale, JGroupsExtension.SUBSYSTEM_RESOLVER.getResourceBundle(locale));
ModelNode result = new ModelNode();
result.get(ModelDescriptionConstants.DESCRIPTION).set(description);
return Collections.singletonMap(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), result);
}
};
Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
String stack = STACK.resolveModelAttribute(context, resource.getModel()).asString();
ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate().registerOverrideModel(context.getCurrentAddressValue(), provider);
PathAddress stackAddress = context.getCurrentAddress().getParent().append(StackResourceDefinition.pathElement(stack));
Resource stackResource = context.readResourceFromRoot(stackAddress, false);
for (String name: stackResource.getChildrenNames(TransportResourceDefinition.WILDCARD_PATH.getKey())) {
PathAddress transportAddress = stackAddress.append(TransportResourceDefinition.pathElement(name));
ModelNode transport = context.readResourceFromRoot(transportAddress, false).getModel();
String moduleName = MODULE.resolveModelAttribute(context, transport).asString();
Class<? extends Protocol> transportClass = findProtocolClass(context, name, moduleName);
registration.registerSubModel(this.createProtocolResourceDefinition(name, transportClass));
resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
}
for (String name: stackResource.getChildrenNames(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) {
Resource protocolResource = context.readResourceFromRoot(stackAddress.append(ProtocolResourceDefinition.pathElement(name)), false);
String moduleName = MODULE.resolveModelAttribute(context, protocolResource.getModel()).asString();
Class<? extends Protocol> protocolClass = findProtocolClass(context, name, moduleName);
registration.registerSubModel(this.createProtocolResourceDefinition(name, protocolClass));
resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
}
if (stackResource.hasChild(RelayResourceDefinition.PATH)) {
registration.registerSubModel(this.createProtocolResourceDefinition(RelayConfiguration.PROTOCOL_NAME, RELAY2.class));
resource.registerChild(ProtocolResourceDefinition.pathElement(RelayConfiguration.PROTOCOL_NAME), PlaceholderResource.INSTANCE);
}
}
@Override
public void unregister(OperationContext context) {
for (String name : context.readResource(PathAddress.EMPTY_ADDRESS).getChildrenNames(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) {
context.removeResource(PathAddress.pathAddress(ProtocolResourceDefinition.pathElement(name)));
}
context.getResourceRegistrationForUpdate().unregisterOverrideModel(context.getCurrentAddressValue());
}
private ResourceDefinition createProtocolResourceDefinition(String protocolName, Class<? extends Protocol> protocolClass) {
SimpleResourceDescriptionResolver resolver = new SimpleResourceDescriptionResolver(protocolName, protocolClass.getSimpleName());
ResourceBuilder builder = ResourceBuilder.Factory.create(ProtocolResourceDefinition.pathElement(protocolName), resolver).setRuntime();
ProtocolMetricsHandler handler = new ProtocolMetricsHandler(this.executors);
for (Map.Entry<String, Attribute> entry: ProtocolMetricsHandler.findProtocolAttributes(protocolClass).entrySet()) {
String name = entry.getKey();
Attribute attribute = entry.getValue();
FieldType type = FieldType.valueOf(attribute.getType());
resolver.addDescription(name, attribute.getDescription());
builder.addMetric(new SimpleAttributeDefinitionBuilder(name, type.getModelType(), true).setStorageRuntime().build(), handler);
}
return builder.build();
}
static Class<? extends Protocol> findProtocolClass(OperationContext context, String protocolName, String moduleName) throws OperationFailedException {
String className = protocolName;
if (moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(Global.PREFIX)) {
className = Global.PREFIX + protocolName;
}
try {
return Module.getContextModuleLoader().loadModule(moduleName).getClassLoader().loadClass(className).asSubclass(Protocol.class);
} catch (ClassNotFoundException | ModuleLoadException e) {
throw JGroupsLogger.ROOT_LOGGER.unableToLoadProtocolClass(className);
}
}
}
| 8,649
| 55.168831
| 219
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolDefaultsServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.logging.JGroupsLogger.ROOT_LOGGER;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jboss.as.clustering.jgroups.ProtocolDefaults;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jgroups.Global;
import org.jgroups.conf.ProtocolStackConfigurator;
import org.jgroups.conf.XmlConfigurator;
import org.jgroups.stack.Protocol;
import org.wildfly.clustering.service.AsyncServiceConfigurator;
import org.wildfly.clustering.service.FunctionalService;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.SimpleServiceNameProvider;
/**
* Service that provides protocol property defaults per protocol type.
* @author Paul Ferraro
*/
public class ProtocolDefaultsServiceConfigurator extends SimpleServiceNameProvider implements ServiceConfigurator, ProtocolDefaults, Supplier<ProtocolDefaults> {
static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append(JGroupsExtension.SUBSYSTEM_NAME, "defaults");
private static final String DEFAULTS = "jgroups-defaults.xml";
private static ProtocolStackConfigurator load(String resource) throws IllegalStateException {
URL url = find(resource, JGroupsExtension.class.getClassLoader());
ROOT_LOGGER.debugf("Loading JGroups protocol defaults from %s", url.toString());
try (InputStream input = url.openStream()) {
return XmlConfigurator.getInstance(input);
} catch (IOException e) {
throw new IllegalArgumentException(JGroupsLogger.ROOT_LOGGER.parserFailure(url));
}
}
private static URL find(String resource, ClassLoader... loaders) {
for (ClassLoader loader: loaders) {
if (loader != null) {
URL url = loader.getResource(resource);
if (url != null) {
return url;
}
}
}
throw new IllegalArgumentException(JGroupsLogger.ROOT_LOGGER.notFound(resource));
}
private final String resource;
private final Map<Class<? extends Protocol>, Map<String, String>> map = new IdentityHashMap<>();
public ProtocolDefaultsServiceConfigurator() {
this(DEFAULTS);
}
public ProtocolDefaultsServiceConfigurator(String resource) {
super(SERVICE_NAME);
this.resource = resource;
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = new AsyncServiceConfigurator(SERVICE_NAME).build(target);
Consumer<ProtocolDefaults> defaults = builder.provides(SERVICE_NAME);
Service service = new FunctionalService<>(defaults, Function.identity(), this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public ProtocolDefaults get() {
ProtocolStackConfigurator configurator = load(ProtocolDefaultsServiceConfigurator.this.resource);
try {
for (org.jgroups.conf.ProtocolConfiguration config: configurator.getProtocolStack()) {
String protocolClassName = Global.PREFIX + config.getProtocolName();
Class<? extends Protocol> protocolClass = Protocol.class.getClassLoader().loadClass(protocolClassName).asSubclass(Protocol.class);
this.map.put(protocolClass, Collections.unmodifiableMap(config.getProperties()));
}
return this;
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
}
@Override
public Map<String, String> getProperties(Class<? extends Protocol> protocolClass) {
Map<String, String> properties = this.map.get(protocolClass);
return (properties != null) ? Collections.unmodifiableMap(properties) : Collections.<String, String>emptyMap();
}
}
| 5,373
| 41.992
| 161
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JDBCProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelType;
/**
* Resource definition override for protocols that require a JDBC DataSource.
* @author Paul Ferraro
*/
public class JDBCProtocolResourceDefinition extends ProtocolResourceDefinition {
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
DATA_SOURCE("data-source", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setCapabilityReference(new CapabilityReference(Capability.PROTOCOL, CommonUnaryRequirement.DATA_SOURCE));
}
},
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(false)
.setRequired(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
private static final class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) {
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor)
.addAttributes(Attribute.class)
.setAddOperationTransformation(new LegacyAddOperationTransformation(Attribute.class))
.setOperationTransformation(LEGACY_OPERATION_TRANSFORMER)
;
}
}
JDBCProtocolResourceDefinition(String name, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(pathElement(name), new ResourceDescriptorConfigurator(configurator), JDBCProtocolConfigurationServiceConfigurator::new, parentServiceConfiguratorFactory);
}
}
| 3,878
| 43.586207
| 168
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ThreadPoolFactoryServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Consumer;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.service.ServiceConfigurator;
/**
* @author Paul Ferraro
*/
public class ThreadPoolFactoryServiceConfigurator extends ThreadPoolServiceNameProvider implements ResourceServiceConfigurator, ThreadPoolConfiguration {
private final ThreadPoolDefinition definition;
private volatile int minThreads = 0;
private volatile int maxThreads = Integer.MAX_VALUE;
private volatile long keepAliveTime = 0;
public ThreadPoolFactoryServiceConfigurator(ThreadPoolDefinition definition, PathAddress address) {
super(address);
this.definition = definition;
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.minThreads = this.definition.getMinThreads().resolveModelAttribute(context, model).asInt();
this.maxThreads = this.definition.getMaxThreads().resolveModelAttribute(context, model).asInt();
this.keepAliveTime = this.definition.getKeepAliveTime().resolveModelAttribute(context, model).asLong();
return this;
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<ThreadPoolConfiguration> factory = builder.provides(this.getServiceName());
Service service = Service.newInstance(factory, this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public int getMinThreads() {
return this.minThreads;
}
@Override
public int getMaxThreads() {
return this.maxThreads;
}
@Override
public long getKeepAliveTime() {
return this.keepAliveTime;
}
}
| 3,304
| 37.882353
| 153
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/RemoteSiteConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.RemoteSiteResourceDefinition.Attribute.CHANNEL;
import java.util.function.Consumer;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.clustering.jgroups.spi.RemoteSiteConfiguration;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class RemoteSiteConfigurationServiceConfigurator extends RemoteSiteServiceNameProvider implements ResourceServiceConfigurator, RemoteSiteConfiguration {
private final String siteName;
private volatile SupplierDependency<String> cluster;
private volatile SupplierDependency<ChannelFactory> factory;
public RemoteSiteConfigurationServiceConfigurator(PathAddress address) {
super(address);
this.siteName = address.getLastElement().getValue();
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<RemoteSiteConfiguration> configuration = new CompositeDependency(this.cluster, this.factory).register(builder).provides(this.getServiceName());
Service service = Service.newInstance(configuration, this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
String channel = CHANNEL.resolveModelAttribute(context, model).asString();
this.cluster = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL_CLUSTER.getServiceName(context, channel));
this.factory = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, channel));
return this;
}
@Override
public String getName() {
return this.siteName;
}
@Override
public ChannelFactory getChannelFactory() {
return this.factory.get();
}
@Override
public String getClusterName() {
return this.cluster.get();
}
}
| 3,840
| 40.75
| 160
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/XMLAttribute.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.HashMap;
import java.util.Map;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
public enum XMLAttribute {
// must be first
UNKNOWN(""),
ALGORITHM(DigestAuthTokenResourceDefinition.Attribute.ALGORITHM),
CHANNEL(RemoteSiteResourceDefinition.Attribute.CHANNEL),
CLIENT_SOCKET_BINDING(SocketProtocolResourceDefinition.Attribute.CLIENT_SOCKET_BINDING),
CLUSTER(ChannelResourceDefinition.Attribute.CLUSTER),
DATA_SOURCE(JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE),
@Deprecated DEFAULT_EXECUTOR("default-executor"),
@Deprecated DEFAULT_STACK("default-stack"),
DEFAULT("default"),
DIAGNOSTICS_SOCKET_BINDING(TransportResourceDefinition.Attribute.DIAGNOSTICS_SOCKET_BINDING),
KEEPALIVE_TIME(ThreadPoolResourceDefinition.DEFAULT.getKeepAliveTime()),
KEY_ALIAS(EncryptProtocolResourceDefinition.Attribute.KEY_ALIAS),
KEY_STORE(EncryptProtocolResourceDefinition.Attribute.KEY_STORE),
MACHINE(TransportResourceDefinition.Attribute.MACHINE),
MAX_THREADS(ThreadPoolResourceDefinition.DEFAULT.getMaxThreads()),
MIN_THREADS(ThreadPoolResourceDefinition.DEFAULT.getMinThreads()),
MODULE(AbstractProtocolResourceDefinition.Attribute.MODULE),
NAME(ModelDescriptionConstants.NAME),
@Deprecated OOB_EXECUTOR("oob-executor"),
OUTBOUND_SOCKET_BINDINGS(SocketDiscoveryProtocolResourceDefinition.Attribute.OUTBOUND_SOCKET_BINDINGS),
QUEUE_LENGTH("queue-length"),
RACK(TransportResourceDefinition.Attribute.RACK),
@Deprecated SHARED("shared"),
SITE(TransportResourceDefinition.Attribute.SITE),
SOCKET_BINDING(MulticastProtocolResourceDefinition.Attribute.SOCKET_BINDING),
STACK(ChannelResourceDefinition.Attribute.STACK),
STATISTICS_ENABLED(ChannelResourceDefinition.Attribute.STATISTICS_ENABLED),
@Deprecated THREAD_FACTORY("thread-factory"),
@Deprecated TIMER_EXECUTOR("timer-executor"),
TYPE(ModelDescriptionConstants.TYPE),
;
private final String name;
XMLAttribute(Attribute attribute) {
this(attribute.getDefinition().getXmlName());
}
XMLAttribute(String name) {
this.name = name;
}
/**
* Get the local name of this element.
*
* @return the local name
*/
public String getLocalName() {
return this.name;
}
private static final Map<String, XMLAttribute> attributes = new HashMap<>();
static {
for (XMLAttribute attribute : values()) {
String name = attribute.getLocalName();
if (name != null) {
attributes.put(name, attribute);
}
}
}
public static XMLAttribute forName(String localName) {
XMLAttribute attribute = attributes.get(localName);
return (attribute != null) ? attribute : UNKNOWN;
}
}
| 3,969
| 38.7
| 107
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/SingletonProtocolServiceNameProvider.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.service.ServiceNameProvider;
/**
* @author Paul Ferraro
*/
public class SingletonProtocolServiceNameProvider implements ServiceNameProvider {
private final ServiceName name;
public SingletonProtocolServiceNameProvider(PathAddress address) {
this(address.getParent(), address.getLastElement());
}
public SingletonProtocolServiceNameProvider(PathAddress stackAddress, PathElement path) {
this.name = StackResourceDefinition.Capability.JCHANNEL_FACTORY.getServiceName(stackAddress).append(path.getKey());
}
@Override
public ServiceName getServiceName() {
return this.name;
}
}
| 1,873
| 36.48
| 123
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelServiceHandler.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Attribute.MODULE;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Attribute.STACK;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Attribute.STATISTICS_ENABLED;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Capability.FORK_CHANNEL_FACTORY;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Capability.JCHANNEL;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Capability.JCHANNEL_FACTORY;
import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Capability.JCHANNEL_MODULE;
import java.util.EnumSet;
import org.jboss.as.clustering.controller.ModuleServiceConfigurator;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.ServiceValueCaptorServiceConfigurator;
import org.jboss.as.clustering.controller.ServiceValueRegistry;
import org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Capability;
import org.jboss.as.clustering.naming.BinderServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.jgroups.JChannel;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.clustering.server.service.DistributedGroupServiceConfiguratorProvider;
import org.wildfly.clustering.server.service.ProvidedGroupServiceConfigurator;
import org.wildfly.clustering.service.IdentityServiceConfigurator;
/**
* @author Paul Ferraro
*/
public class ChannelServiceHandler implements ResourceServiceHandler {
private final ServiceValueRegistry<JChannel> registry;
public ChannelServiceHandler(ServiceValueRegistry<JChannel> registry) {
this.registry = registry;
}
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
String name = context.getCurrentAddressValue();
String stack = STACK.resolveModelAttribute(context, model).asString();
ServiceTarget target = context.getServiceTarget();
new ChannelClusterServiceConfigurator(address).configure(context, model).build(target).install();
ChannelServiceConfigurator channelBuilder = new ChannelServiceConfigurator(JCHANNEL, address).statisticsEnabled(STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean());
channelBuilder.configure(context, model).build(target).install();
new IdentityServiceConfigurator<>(JCHANNEL_FACTORY.getServiceName(address), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stack)).build(target).install();
new ForkChannelFactoryServiceConfigurator(FORK_CHANNEL_FACTORY, address.append(ForkResourceDefinition.pathElement(name))).configure(context, new ModelNode()).build(target).install();
new ModuleServiceConfigurator(JCHANNEL_MODULE.getServiceName(address), MODULE).configure(context, model).build(target).setInitialMode(ServiceController.Mode.PASSIVE).install();
new ServiceValueCaptorServiceConfigurator<>(this.registry.add(channelBuilder.getServiceName())).build(target).install();
new BinderServiceConfigurator(JGroupsBindingFactory.createChannelBinding(name), JGroupsRequirement.CHANNEL.getServiceName(context, name)).build(target).install();
new BinderServiceConfigurator(JGroupsBindingFactory.createChannelFactoryBinding(name), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, name)).build(target).install();
// Install group services for channel
new ProvidedGroupServiceConfigurator<>(DistributedGroupServiceConfiguratorProvider.class, name).configure(context).build(target).install();
}
@Override
public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
String name = context.getCurrentAddressValue();
for (Capability capability : EnumSet.allOf(Capability.class)) {
context.removeService(capability.getServiceName(address));
}
context.removeService(JGroupsBindingFactory.createChannelBinding(name).getBinderServiceName());
context.removeService(JGroupsBindingFactory.createChannelFactoryBinding(name).getBinderServiceName());
// Remove group services for channel
new ProvidedGroupServiceConfigurator<>(DistributedGroupServiceConfiguratorProvider.class, name).remove(context);
context.removeService(new ServiceValueCaptorServiceConfigurator<>(this.registry.remove(JCHANNEL.getServiceName(address))).getServiceName());
}
}
| 6,092
| 56.481132
| 190
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/RelayConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.RelayResourceDefinition.Attribute.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jgroups.JChannel;
import org.jgroups.protocols.FORK;
import org.jgroups.protocols.relay.RELAY2;
import org.jgroups.protocols.relay.config.RelayConfig;
import org.wildfly.clustering.jgroups.spi.RelayConfiguration;
import org.wildfly.clustering.jgroups.spi.RemoteSiteConfiguration;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceNameProvider;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class RelayConfigurationServiceConfigurator extends AbstractProtocolConfigurationServiceConfigurator<RELAY2, RelayConfiguration> implements RelayConfiguration {
private final ServiceNameProvider provider;
private volatile List<SupplierDependency<RemoteSiteConfiguration>> sites;
private volatile String siteName = null;
public RelayConfigurationServiceConfigurator(PathAddress address) {
super(address.getLastElement().getValue());
this.provider = new SingletonProtocolServiceNameProvider(address);
}
@Override
public ServiceName getServiceName() {
return this.provider.getServiceName();
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
for (Dependency dependency : this.sites) {
dependency.register(builder);
}
return super.register(builder);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.siteName = SITE.resolveModelAttribute(context, model).asString();
PathAddress address = context.getCurrentAddress();
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
Set<Resource.ResourceEntry> entries = resource.getChildren(RemoteSiteResourceDefinition.WILDCARD_PATH.getKey());
this.sites = new ArrayList<>(entries.size());
for (Resource.ResourceEntry entry : entries) {
this.sites.add(new ServiceSupplierDependency<>(new RemoteSiteServiceNameProvider(address, entry.getPathElement())));
}
return super.configure(context, model);
}
@Override
public RelayConfiguration get() {
return this;
}
@Override
public String getSiteName() {
return this.siteName;
}
@Override
public List<RemoteSiteConfiguration> getRemoteSites() {
List<RemoteSiteConfiguration> result = new ArrayList<>(this.sites.size());
for (Supplier<RemoteSiteConfiguration> site : this.sites) {
result.add(site.get());
}
return result;
}
@Override
public void accept(RELAY2 protocol) {
String localSite = this.siteName;
List<RemoteSiteConfiguration> remoteSites = this.getRemoteSites();
List<String> sites = new ArrayList<>(remoteSites.size() + 1);
sites.add(localSite);
// Collect bridges, eliminating duplicates
Map<String, RelayConfig.BridgeConfig> bridges = new HashMap<>();
for (final RemoteSiteConfiguration remoteSite: remoteSites) {
String siteName = remoteSite.getName();
sites.add(siteName);
String clusterName = remoteSite.getClusterName();
RelayConfig.BridgeConfig bridge = new RelayConfig.BridgeConfig(clusterName) {
@Override
public JChannel createChannel() throws Exception {
JChannel channel = remoteSite.getChannelFactory().createChannel(siteName);
// Don't use FORK in bridge stack
channel.getProtocolStack().removeProtocol(FORK.class);
return channel;
}
};
bridges.put(clusterName, bridge);
}
protocol.site(localSite);
for (String site: sites) {
RelayConfig.SiteConfig siteConfig = new RelayConfig.SiteConfig(site);
protocol.addSite(site, siteConfig);
if (site.equals(localSite)) {
for (RelayConfig.BridgeConfig bridge: bridges.values()) {
siteConfig.addBridge(bridge);
}
}
}
}
}
| 5,954
| 38.966443
| 167
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsExtensionTransformerRegistration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.ExtensionTransformerRegistration;
import org.jboss.as.controller.transform.SubsystemTransformerRegistration;
import org.jboss.as.controller.transform.description.TransformationDescription;
import org.kohsuke.MetaInfServices;
/**
* Registration for JGroups subsystem transformers.
* @author Paul Ferraro
*/
@MetaInfServices(ExtensionTransformerRegistration.class)
public class JGroupsExtensionTransformerRegistration implements ExtensionTransformerRegistration {
@Override
public String getSubsystemName() {
return JGroupsExtension.SUBSYSTEM_NAME;
}
@Override
public void registerTransformers(SubsystemTransformerRegistration registration) {
// Register transformers for all but the current model
for (JGroupsSubsystemModel model : EnumSet.complementOf(EnumSet.of(JGroupsSubsystemModel.CURRENT))) {
ModelVersion version = model.getVersion();
TransformationDescription.Tools.register(new JGroupsSubsystemResourceTransformer().apply(version), registration, version);
}
}
}
| 2,245
| 40.592593
| 134
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/LegacyFailureDetectionProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.ClientMapping;
import org.jboss.as.network.SocketBinding;
import org.jgroups.protocols.FD_SOCK;
/**
* @author Paul Ferraro
*/
public class LegacyFailureDetectionProtocolConfigurationServiceConfigurator extends SocketProtocolConfigurationServiceConfigurator<FD_SOCK> {
public LegacyFailureDetectionProtocolConfigurationServiceConfigurator(PathAddress address) {
super(address);
}
@Override
public Map<String, SocketBinding> getSocketBindings() {
Map<String, SocketBinding> result = new TreeMap<>();
SocketBinding binding = this.getSocketBinding();
if (binding != null) {
result.put("jgroups.fd_sock.srv_sock", binding);
}
SocketBinding clientBinding = this.getClientSocketBinding();
if (clientBinding != null) {
result.put("jgroups.fd.ping_sock", clientBinding);
}
return result;
}
@Override
public void accept(FD_SOCK protocol) {
// If binding is undefined, protocol will use bind address of transport and a random ephemeral port
SocketBinding binding = this.getSocketBinding();
protocol.setStartPort((binding != null) ? binding.getAbsolutePort() : 0);
if (binding != null) {
protocol.setBindAddress(binding.getAddress());
List<ClientMapping> clientMappings = binding.getClientMappings();
if (!clientMappings.isEmpty()) {
// JGroups cannot select a client mapping based on the source address, so just use the first one
ClientMapping mapping = clientMappings.get(0);
try {
protocol.setExternalAddress(InetAddress.getByName(mapping.getDestinationAddress()));
protocol.setExternalPort(mapping.getDestinationPort());
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e);
}
}
}
SocketBinding clientBinding = this.getClientSocketBinding();
if (clientBinding != null) {
protocol.setClientBindPort(clientBinding.getSocketAddress().getPort());
}
}
}
| 3,448
| 39.104651
| 141
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AuthTokenServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.AuthTokenResourceDefinition.Capability.AUTH_TOKEN;
import java.io.IOException;
import java.util.function.Consumer;
import java.util.function.Function;
import org.jboss.as.clustering.controller.CapabilityServiceNameProvider;
import org.jboss.as.clustering.controller.CredentialSourceDependency;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.jgroups.auth.AuthToken;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.FunctionalService;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.SupplierDependency;
import org.wildfly.security.credential.PasswordCredential;
import org.wildfly.security.credential.source.CredentialSource;
import org.wildfly.security.password.interfaces.ClearPassword;
/**
* @author Paul Ferraro
*/
public abstract class AuthTokenServiceConfigurator<T extends AuthToken> extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, Function<String, T>, Dependency {
private static final Function<CredentialSource, String> CREDENTIAL_SOURCE_MAPPER = new Function<>() {
@Override
public String apply(CredentialSource sharedSecretSource) {
try {
PasswordCredential credential = sharedSecretSource.getCredential(PasswordCredential.class);
ClearPassword password = credential.getPassword(ClearPassword.class);
return String.valueOf(password.getPassword());
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
};
private volatile SupplierDependency<CredentialSource> sharedSecretSource;
public AuthTokenServiceConfigurator(PathAddress address) {
super(AUTH_TOKEN, address);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.sharedSecretSource = new CredentialSourceDependency(context, AuthTokenResourceDefinition.Attribute.SHARED_SECRET, model);
return this;
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<T> token = this.register(builder).provides(this.getServiceName());
Service service = new FunctionalService<>(token, CREDENTIAL_SOURCE_MAPPER.andThen(this), this.sharedSecretSource);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public <V> ServiceBuilder<V> register(ServiceBuilder<V> builder) {
return this.sharedSecretSource.register(builder);
}
}
| 4,192
| 43.606383
| 183
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ForkResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Consumer;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for fork channel resources.
* @author Paul Ferraro
*/
public class ForkResourceTransformer implements Consumer<ModelVersion> {
private final ResourceTransformationDescriptionBuilder builder;
ForkResourceTransformer(ResourceTransformationDescriptionBuilder parent) {
this.builder = parent.addChildResource(ForkResourceDefinition.WILDCARD_PATH);
}
@Override
public void accept(ModelVersion version) {
new ProtocolTransformer(this.builder).accept(version);
}
}
| 1,776
| 36.808511
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for protocol resources.
* @author Paul Ferraro
*/
public class ProtocolResourceTransformer extends AbstractProtocolResourceTransformer {
ProtocolResourceTransformer(ResourceTransformationDescriptionBuilder builder) {
super(builder);
}
}
| 1,447
| 38.135135
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsBindingFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.naming.JndiNameFactory;
import org.jboss.as.naming.deployment.ContextNames;
public final class JGroupsBindingFactory {
public static ContextNames.BindInfo createChannelBinding(String channel) {
return ContextNames.bindInfoFor(JndiNameFactory.createJndiName(JndiNameFactory.DEFAULT_JNDI_NAMESPACE, JGroupsExtension.SUBSYSTEM_NAME, "channel", channel).getAbsoluteName());
}
public static ContextNames.BindInfo createChannelFactoryBinding(String stack) {
return ContextNames.bindInfoFor(JndiNameFactory.createJndiName(JndiNameFactory.DEFAULT_JNDI_NAMESPACE, JGroupsExtension.SUBSYSTEM_NAME, "factory", stack).getAbsoluteName());
}
private JGroupsBindingFactory() {
// Hide
}
}
| 1,832
| 43.707317
| 183
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/EncryptProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.EncryptProtocolResourceDefinition.Attribute.KEY_ALIAS;
import static org.jboss.as.clustering.jgroups.subsystem.EncryptProtocolResourceDefinition.Attribute.KEY_CREDENTIAL;
import static org.jboss.as.clustering.jgroups.subsystem.EncryptProtocolResourceDefinition.Attribute.KEY_STORE;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableEntryException;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.CredentialSourceDependency;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jgroups.protocols.Encrypt;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
import org.wildfly.security.credential.PasswordCredential;
import org.wildfly.security.credential.source.CredentialSource;
import org.wildfly.security.password.interfaces.ClearPassword;
/**
* @author Paul Ferraro
*/
public class EncryptProtocolConfigurationServiceConfigurator<E extends KeyStore.Entry, P extends Encrypt<E>> extends ProtocolConfigurationServiceConfigurator<P> {
private final Class<E> entryClass;
private volatile SupplierDependency<KeyStore> keyStore;
private volatile SupplierDependency<CredentialSource> credentialSource;
private volatile String keyAlias;
public EncryptProtocolConfigurationServiceConfigurator(PathAddress address, Class<E> entryClass) {
super(address);
this.entryClass = entryClass;
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
String keyStore = KEY_STORE.resolveModelAttribute(context, model).asString();
this.keyStore = new ServiceSupplierDependency<>(CommonUnaryRequirement.KEY_STORE.getServiceName(context, keyStore));
this.keyAlias = KEY_ALIAS.resolveModelAttribute(context, model).asString();
this.credentialSource = new CredentialSourceDependency(context, KEY_CREDENTIAL, model);
return super.configure(context, model);
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
return super.register(new CompositeDependency(this.keyStore, this.credentialSource).register(builder));
}
@Override
public void accept(P protocol) {
KeyStore store = this.keyStore.get();
String alias = this.keyAlias;
try {
if (!store.containsAlias(alias)) {
throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias);
}
PasswordCredential credential = this.credentialSource.get().getCredential(PasswordCredential.class);
if (credential == null) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
}
ClearPassword password = credential.getPassword(ClearPassword.class);
if (password == null) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
}
if (!store.entryInstanceOf(alias, this.entryClass)) {
throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, this.entryClass.getSimpleName());
}
KeyStore.Entry entry = store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
protocol.setKeyStoreEntry(this.entryClass.cast(entry));
} catch (KeyStoreException | IOException | NoSuchAlgorithmException | UnrecoverableEntryException e) {
throw new IllegalArgumentException(e);
}
}
}
| 5,164
| 46.824074
| 162
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/TransportResourceRegistrar.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import org.jboss.as.clustering.controller.ManagementRegistrar;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
/**
* Registers transport definitions, including any definition overrides.
* @author Paul Ferraro
*/
public class TransportResourceRegistrar implements ManagementRegistrar<ManagementResourceRegistration> {
enum MulticastTransport {
UDP;
}
enum SocketTransport {
TCP, TCP_NIO2;
}
private final ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory;
public TransportResourceRegistrar(ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
this.parentServiceConfiguratorFactory = parentServiceConfiguratorFactory;
}
@Override
public void register(ManagementResourceRegistration registration) {
new TransportResourceDefinition(this.parentServiceConfiguratorFactory).register(registration);
for (MulticastTransport transport : EnumSet.allOf(MulticastTransport.class)) {
new TransportResourceDefinition(transport.name(), MulticastTransportConfigurationServiceConfigurator::new, this.parentServiceConfiguratorFactory).register(registration);
}
for (SocketTransport transport : EnumSet.allOf(SocketTransport.class)) {
new SocketTransportResourceDefinition(transport.name(), SocketTransportConfigurationServiceConfigurator::new, this.parentServiceConfiguratorFactory).register(registration);
}
}
}
| 2,674
| 40.796875
| 184
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/PlainAuthTokenResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.jgroups.auth.BinaryAuthToken;
import org.jboss.as.controller.PathElement;
/**
* @author Paul Ferraro
*/
public class PlainAuthTokenResourceDefinition extends AuthTokenResourceDefinition<BinaryAuthToken> {
static final PathElement PATH = pathElement("plain");
PlainAuthTokenResourceDefinition() {
super(PATH, UnaryOperator.identity(), PlainAuthTokenServiceConfigurator::new);
}
}
| 1,553
| 36.902439
| 100
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/CipherAuthTokenResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.jgroups.auth.CipherAuthToken;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.security.CredentialReference;
import org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* @author Paul Ferraro
*/
public class CipherAuthTokenResourceDefinition extends AuthTokenResourceDefinition<CipherAuthToken> {
static final PathElement PATH = pathElement("cipher");
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
KEY_CREDENTIAL(CredentialReference.getAttributeBuilder("key-credential-reference", null, false, new CapabilityReference(Capability.AUTH_TOKEN, CommonUnaryRequirement.CREDENTIAL_STORE)).build()),
KEY_ALIAS("key-alias", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setAllowExpression(true);
}
},
KEY_STORE("key-store", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setCapabilityReference(new CapabilityReference(Capability.AUTH_TOKEN, CommonUnaryRequirement.KEY_STORE));
}
},
ALGORITHM("algorithm", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setAllowExpression(true)
.setRequired(false)
.setDefaultValue(new ModelNode("RSA"))
;
}
},
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setRequired(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
Attribute(AttributeDefinition definition) {
this.definition = definition;
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder;
}
}
static class ResourceDescriptorTransformer implements UnaryOperator<ResourceDescriptor> {
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return descriptor.addAttributes(EnumSet.complementOf(EnumSet.of(Attribute.KEY_CREDENTIAL)))
.addAttribute(Attribute.KEY_CREDENTIAL, new CredentialReferenceWriteAttributeHandler(Attribute.KEY_CREDENTIAL.getDefinition()));
}
}
CipherAuthTokenResourceDefinition() {
super(PATH, new ResourceDescriptorTransformer(), CipherAuthTokenServiceConfigurator::new);
}
}
| 4,680
| 42.342593
| 202
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AuthProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.msc.service.ServiceBuilder;
import org.jgroups.auth.AuthToken;
import org.jgroups.protocols.AUTH;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class AuthProtocolConfigurationServiceConfigurator extends ProtocolConfigurationServiceConfigurator<AUTH> {
private final SupplierDependency<AuthToken> token;
public AuthProtocolConfigurationServiceConfigurator(PathAddress address) {
super(address);
this.token = new ServiceSupplierDependency<>(AuthTokenResourceDefinition.Capability.AUTH_TOKEN.getServiceName(address.append(AuthTokenResourceDefinition.WILDCARD_PATH)));
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
return super.register(this.token.register(builder));
}
@Override
public void accept(AUTH protocol) {
protocol.setAuthToken(this.token.get());
}
}
| 2,116
| 38.203704
| 178
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/CipherAuthTokenResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.security.CredentialReference;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for cipher auth token resources.
* @author Paul Ferraro
*/
public class CipherAuthTokenResourceTransformer extends AuthTokenResourceTransformer {
CipherAuthTokenResourceTransformer(ResourceTransformationDescriptionBuilder parent) {
super(parent.addChildResource(CipherAuthTokenResourceDefinition.PATH));
}
@Override
public void accept(ModelVersion version) {
if (JGroupsSubsystemModel.VERSION_8_0_0.requiresTransformation(version)) {
this.builder.getAttributeBuilder()
.addRejectCheck(CredentialReference.REJECT_CREDENTIAL_REFERENCE_WITH_BOTH_STORE_AND_CLEAR_TEXT, CipherAuthTokenResourceDefinition.Attribute.KEY_CREDENTIAL.getName())
.end();
}
super.accept(version);
}
}
| 2,077
| 41.408163
| 185
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/StackServiceHandler.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.SimpleResourceServiceHandler;
import org.jboss.as.clustering.naming.BinderServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.dmr.ModelNode;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
/**
* @author Paul Ferraro
*/
public class StackServiceHandler extends SimpleResourceServiceHandler {
StackServiceHandler(ResourceServiceConfiguratorFactory factory) {
super(factory);
}
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
super.installServices(context, model);
String name = context.getCurrentAddressValue();
new BinderServiceConfigurator(JGroupsBindingFactory.createChannelFactoryBinding(name), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, name)).build(context.getServiceTarget()).install();
}
@Override
public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException {
String name = context.getCurrentAddressValue();
context.removeService(JGroupsBindingFactory.createChannelFactoryBinding(name).getBinderServiceName());
super.removeServices(context, model);
}
}
| 2,484
| 40.416667
| 205
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/StackOperationHandler.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jboss.as.clustering.controller.Operation;
import org.jboss.as.clustering.controller.ManagementRegistrar;
import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver;
import org.jboss.as.controller.AbstractRuntimeOnlyHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.LifecycleEvent;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.clustering.service.CountDownLifecycleListener;
import org.wildfly.clustering.service.FunctionalService;
/**
* Operation handler for protocol stack diagnostic runtime operations.
* @author Paul Ferraro
*/
public class StackOperationHandler extends AbstractRuntimeOnlyHandler implements ManagementRegistrar<ManagementResourceRegistration> {
private final Map<String, Operation<ChannelFactory>> operations = new HashMap<>();
public StackOperationHandler() {
for (Operation<ChannelFactory> operation : EnumSet.allOf(StackOperation.class)) {
this.operations.put(operation.getName(), operation);
}
}
/* Method is synchronized to avoid duplicate service exceptions if called concurrently */
@Override
protected synchronized void executeRuntimeStep(OperationContext context, ModelNode op) throws OperationFailedException {
String name = op.get(ModelDescriptionConstants.OP).asString();
Operation<ChannelFactory> operation = this.operations.get(name);
ServiceName serviceName = JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, UnaryCapabilityNameResolver.DEFAULT);
Function<ChannelFactory, ModelNode> operationFunction = new Function<>() {
@Override
public ModelNode apply(ChannelFactory factory) {
try {
return operation.execute(context, op, factory);
} catch (OperationFailedException e) {
throw new RuntimeException(e);
}
}
};
ServiceBuilder<?> builder = context.getServiceTarget().addService(serviceName.append(this.getClass().getSimpleName()));
Supplier<ChannelFactory> factory = builder.requires(serviceName);
Reference<ModelNode> reference = new Reference<>();
CountDownLatch startLatch = new CountDownLatch(1);
CountDownLatch removeLatch = new CountDownLatch(1);
ServiceController<?> controller = builder
.addListener(new CountDownLifecycleListener(startLatch, EnumSet.of(LifecycleEvent.UP, LifecycleEvent.FAILED)))
.addListener(new CountDownLifecycleListener(removeLatch, EnumSet.of(LifecycleEvent.REMOVED)))
.setInstance(new FunctionalService<>(reference, operationFunction, factory))
// Force ChannelFactory service to start
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
try {
startLatch.await();
ModelNode result = reference.get();
if (result != null) {
context.getResult().set(result);
} else {
context.getFailureDescription().set(controller.getStartException().getLocalizedMessage());
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new OperationFailedException(e);
} finally {
// Make sure service is removed
try {
controller.setMode(ServiceController.Mode.REMOVE);
removeLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}
@Override
public void register(ManagementResourceRegistration registration) {
for (Operation<ChannelFactory> operation : EnumSet.allOf(StackOperation.class)) {
registration.registerOperationHandler(operation.getDefinition(), this);
}
}
static class Reference<T> implements Consumer<T>, Supplier<T> {
private volatile T value;
@Override
public T get() {
return this.value;
}
@Override
public void accept(T value) {
this.value = value;
}
}
}
| 6,046
| 43.138686
| 134
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/StackOperation.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.jboss.as.clustering.controller.Operation;
import org.jboss.as.controller.ExpressionResolver;
import org.jboss.as.controller.OperationDefinition;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jgroups.JChannel;
import org.jgroups.stack.Protocol;
import org.jgroups.stack.ProtocolStack;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
/**
* @author Paul Ferraro
*/
public enum StackOperation implements Operation<ChannelFactory> {
EXPORT_NATIVE_CONFIGURATION("export-native-configuration", ModelType.STRING) {
@Override
public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ChannelFactory factory) throws OperationFailedException {
// Create a temporary channel, but don't connect it
try (JChannel channel = factory.createChannel(UUID.randomUUID().toString())) {
// ProtocolStack.printProtocolSpecAsXML() is very hacky and only works on an uninitialized stack
List<Protocol> protocols = channel.getProtocolStack().getProtocols();
Collections.reverse(protocols);
ProtocolStack stack = new ProtocolStack();
stack.addProtocols(protocols);
return new ModelNode(stack.printProtocolSpecAsXML());
} catch (Exception e) {
throw new OperationFailedException(e);
}
}
},
;
private final OperationDefinition definition;
StackOperation(String name, ModelType replyType) {
this.definition = new SimpleOperationDefinitionBuilder(name, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(StackResourceDefinition.WILDCARD_PATH)).setReplyType(replyType).setReadOnly().build();
}
@Override
public OperationDefinition getDefinition() {
return this.definition;
}
}
| 3,143
| 41.486486
| 211
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/MulticastProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelType;
/**
* Resource definition override for protocols that require a socket-binding.
* @author Paul Ferraro
*/
public class MulticastProtocolResourceDefinition extends ProtocolResourceDefinition {
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
SOCKET_BINDING(ModelDescriptionConstants.SOCKET_BINDING, ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.setCapabilityReference(new CapabilityReference(Capability.PROTOCOL, CommonUnaryRequirement.SOCKET_BINDING))
;
}
},
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setRequired(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) {
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor).addAttributes(Attribute.class);
}
}
MulticastProtocolResourceDefinition(String name, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(pathElement(name), new ResourceDescriptorConfigurator(configurator), MulticastSocketProtocolConfigurationServiceConfigurator::new, parentServiceConfiguratorFactory);
}
}
| 3,948
| 44.918605
| 179
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AuthProtocolResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for auth protocol resources.
* @author Paul Ferraro
*/
public class AuthProtocolResourceTransformer extends ProtocolResourceTransformer {
AuthProtocolResourceTransformer(ResourceTransformationDescriptionBuilder builder) {
super(builder);
}
@Override
public void accept(ModelVersion version) {
new CipherAuthTokenResourceTransformer(this.builder).accept(version);
new DigestAuthTokenResourceTransformer(this.builder).accept(version);
new PlainAuthTokenResourceTransformer(this.builder).accept(version);
super.accept(version);
}
}
| 1,831
| 37.166667
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemXMLReader.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.clustering.logging.ClusteringLogger;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.AttributeParser;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* XML reader for the JGroups subsystem.
* @author Paul Ferraro
*/
@SuppressWarnings({ "deprecation", "static-method" })
public class JGroupsSubsystemXMLReader implements XMLElementReader<List<ModelNode>> {
private final JGroupsSubsystemSchema schema;
JGroupsSubsystemXMLReader(JGroupsSubsystemSchema schema) {
this.schema = schema;
}
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> result) throws XMLStreamException {
Map<PathAddress, ModelNode> operations = new LinkedHashMap<>();
PathAddress address = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
String defaultStack = null;
if (!this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
defaultStack = require(reader, XMLAttribute.DEFAULT_STACK);
// Fabricate a default channel
PathAddress channelAddress = address.append(ChannelResourceDefinition.pathElement("ee"));
ModelNode channelOperation = Util.createAddOperation(channelAddress);
channelOperation.get(ChannelResourceDefinition.Attribute.STACK.getName()).set(defaultStack);
channelOperation.get(ChannelResourceDefinition.Attribute.CLUSTER.getName()).set("ejb");
operations.put(channelAddress, channelOperation);
operation.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName()).set(channelAddress.getLastElement().getValue());
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case CHANNELS: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
this.parseChannels(reader, address, operations);
break;
}
}
case STACKS: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
defaultStack = this.parseStacks(reader, address, operations, defaultStack);
break;
}
}
case STACK: {
if (!this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
this.parseStack(reader, address, operations, defaultStack);
break;
}
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
// Version prior to 4_0 schema did not require stack being defined,
// thus iterate over channel add operations and set the stack explicitly.
if (!this.schema.since(JGroupsSubsystemSchema.VERSION_4_0)) {
for (Map.Entry<PathAddress, ModelNode> entry : operations.entrySet()) {
PathAddress opAddr = entry.getKey();
if (opAddr.getLastElement().getKey().equals(ChannelResourceDefinition.WILDCARD_PATH.getKey())) {
ModelNode op = entry.getValue();
if (!op.hasDefined(ChannelResourceDefinition.Attribute.STACK.getName())) {
op.get(ChannelResourceDefinition.Attribute.STACK.getName()).set(defaultStack);
}
}
}
}
result.addAll(operations.values());
}
private void parseChannels(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case DEFAULT: {
readAttribute(reader, i, operation, JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case CHANNEL: {
this.parseChannel(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseChannel(XMLExtendedStreamReader reader, PathAddress subsystemAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String name = require(reader, XMLAttribute.NAME);
PathAddress address = subsystemAddress.append(ChannelResourceDefinition.pathElement(name));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
case STACK: {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.STACK);
break;
}
case MODULE: {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.MODULE);
break;
}
case CLUSTER: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_4_0)) {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.CLUSTER);
break;
}
}
case STATISTICS_ENABLED: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.STATISTICS_ENABLED);
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (this.schema.since(JGroupsSubsystemSchema.VERSION_4_0)) {
require(reader, operation, ChannelResourceDefinition.Attribute.STACK);
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case FORK: {
this.parseFork(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseFork(XMLExtendedStreamReader reader, PathAddress channelAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String name = require(reader, XMLAttribute.NAME);
PathAddress address = channelAddress.append(ForkResourceDefinition.pathElement(name));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case PROTOCOL: {
this.parseProtocol(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private String parseStacks(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations, String legacyDefaultStack) throws XMLStreamException {
String defaultStack = legacyDefaultStack;
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case DEFAULT: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_9_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
defaultStack = reader.getAttributeValue(i);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case STACK: {
this.parseStack(reader, address, operations, defaultStack);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
return defaultStack;
}
private void parseStack(XMLExtendedStreamReader reader, PathAddress subsystemAddress, Map<PathAddress, ModelNode> operations, String defaultStack) throws XMLStreamException {
String name = require(reader, XMLAttribute.NAME);
PathAddress address = subsystemAddress.append(StackResourceDefinition.pathElement(name));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
case STATISTICS_ENABLED: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
readAttribute(reader, i, operation, StackResourceDefinition.Attribute.STATISTICS_ENABLED);
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case TRANSPORT: {
this.parseTransport(reader, address, operations);
break;
}
case PROTOCOL: {
// If protocol contains socket-binding attribute, parse as a socket-protocol
if (reader.getAttributeValue(null, SocketProtocolResourceDefinition.Attribute.SOCKET_BINDING.getDefinition().getXmlName()) != null) {
this.parseSocketProtocol(reader, address, operations);
} else {
this.parseProtocol(reader, address, operations);
}
break;
}
case RELAY: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_2_0)) {
this.parseRelay(reader, address, operations, defaultStack);
break;
}
}
case SOCKET_PROTOCOL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
this.parseSocketProtocol(reader, address, operations);
break;
}
}
case SOCKET_DISCOVERY_PROTOCOL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
this.parseSocketDiscoveryProtocol(reader, address, operations);
break;
}
}
case JDBC_PROTOCOL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
this.parseJDBCProtocol(reader, address, operations);
break;
}
}
case ENCRYPT_PROTOCOL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
this.parseEncryptProtocol(reader, address, operations);
break;
}
}
case AUTH_PROTOCOL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
this.parseAuthProtocol(reader, address, operations);
break;
}
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseTransport(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(TransportResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case SOCKET_BINDING: {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.SOCKET_BINDING);
break;
}
case DIAGNOSTICS_SOCKET_BINDING: {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.DIAGNOSTICS_SOCKET_BINDING);
break;
}
case SHARED:
case DEFAULT_EXECUTOR:
case OOB_EXECUTOR:
case TIMER_EXECUTOR:
case THREAD_FACTORY:
if (this.schema.since(JGroupsSubsystemSchema.VERSION_9_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
ClusteringLogger.ROOT_LOGGER.attributeIgnored(attribute.getLocalName(), reader.getLocalName());
break;
case SITE: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_1_1)) {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.SITE);
break;
}
}
case RACK: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_1_1)) {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.RACK);
break;
}
}
case MACHINE: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_1_1)) {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.MACHINE);
break;
}
}
case CLIENT_SOCKET_BINDING: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_7_0)) {
readAttribute(reader, i, operation, SocketTransportResourceDefinition.Attribute.CLIENT_SOCKET_BINDING);
break;
}
}
default: {
this.parseProtocolAttribute(reader, i, operation);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case DEFAULT_THREAD_POOL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.DEFAULT, reader, address, operations);
break;
}
}
case INTERNAL_THREAD_POOL:
case OOB_THREAD_POOL:
case TIMER_THREAD_POOL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_6_0)) {
throw ParseUtils.unexpectedElement(reader);
}
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
ParseUtils.requireNoContent(reader);
break;
}
}
default: {
this.parseProtocolElement(reader, address, operations);
}
}
}
// Set default port_range for pre-WF11 schemas
if (!this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
String portRangeProperty = "port_range";
if (!operation.hasDefined(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), portRangeProperty)) {
operation.get(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName()).get(portRangeProperty).set("50");
}
}
}
private void parseSocketProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case SOCKET_BINDING: {
readAttribute(reader, i, operation, SocketProtocolResourceDefinition.Attribute.SOCKET_BINDING);
break;
}
case CLIENT_SOCKET_BINDING: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_7_0)) {
readAttribute(reader, i, operation, SocketProtocolResourceDefinition.Attribute.CLIENT_SOCKET_BINDING);
break;
}
}
default: {
parseProtocolAttribute(reader, i, operation);
}
}
}
require(reader, operation, SocketProtocolResourceDefinition.Attribute.SOCKET_BINDING);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseSocketDiscoveryProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case OUTBOUND_SOCKET_BINDINGS: {
readAttribute(reader, i, operation, SocketDiscoveryProtocolResourceDefinition.Attribute.OUTBOUND_SOCKET_BINDINGS);
break;
}
default: {
parseProtocolAttribute(reader, i, operation);
}
}
}
require(reader, operation, SocketDiscoveryProtocolResourceDefinition.Attribute.OUTBOUND_SOCKET_BINDINGS);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseJDBCProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case DATA_SOURCE: {
readAttribute(reader, i, operation, JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE);
break;
}
default: {
parseProtocolAttribute(reader, i, operation);
}
}
}
require(reader, operation, JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseEncryptProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case KEY_ALIAS: {
readAttribute(reader, i, operation, EncryptProtocolResourceDefinition.Attribute.KEY_ALIAS);
break;
}
case KEY_STORE: {
readAttribute(reader, i, operation, EncryptProtocolResourceDefinition.Attribute.KEY_STORE);
break;
}
default: {
parseProtocolAttribute(reader, i, operation);
}
}
}
require(reader, operation, EncryptProtocolResourceDefinition.Attribute.KEY_ALIAS, EncryptProtocolResourceDefinition.Attribute.KEY_STORE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseEncryptProtocolElement(reader, address, operations);
}
}
private void parseAuthProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseProtocolAttribute(reader, i, operation);
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseAuthProtocolElement(reader, address, operations);
}
if (!operations.containsKey(address.append(AuthTokenResourceDefinition.WILDCARD_PATH))) {
throw ParseUtils.missingOneOf(reader, EnumSet.of(XMLElement.PLAIN_TOKEN, XMLElement.DIGEST_TOKEN, XMLElement.CIPHER_TOKEN));
}
}
private void parseProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseProtocolAttribute(reader, i, operation);
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseProtocolAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation) throws XMLStreamException {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(index));
switch (attribute) {
case TYPE: {
// Already parsed
break;
}
case DATA_SOURCE: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
throw ParseUtils.unexpectedAttribute(reader, index);
}
readAttribute(reader, index, operation, JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE);
break;
}
case MODULE: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
readAttribute(reader, index, operation, AbstractProtocolResourceDefinition.Attribute.MODULE);
break;
}
}
case STATISTICS_ENABLED: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_5_0)) {
readAttribute(reader, index, operation, AbstractProtocolResourceDefinition.Attribute.STATISTICS_ENABLED);
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, index);
}
}
}
private void parseEncryptProtocolElement(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case KEY_CREDENTIAL_REFERENCE: {
readElement(reader, operation, EncryptProtocolResourceDefinition.Attribute.KEY_CREDENTIAL);
break;
}
default: {
this.parseProtocolElement(reader, address, operations);
}
}
}
private void parseAuthProtocolElement(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case PLAIN_TOKEN: {
this.parsePlainAuthToken(reader, address, operations);
break;
}
case DIGEST_TOKEN: {
this.parseDigestAuthToken(reader, address, operations);
break;
}
case CIPHER_TOKEN: {
this.parseCipherAuthToken(reader, address, operations);
break;
}
default: {
this.parseProtocolElement(reader, address, operations);
}
}
}
private void parseProtocolElement(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case PROPERTY: {
this.parseProperty(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
private void parsePlainAuthToken(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = protocolAddress.append(PlainAuthTokenResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH), operation);
ParseUtils.requireNoAttributes(reader);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseAuthTokenElement(reader, protocolAddress, operations);
}
require(reader, operation, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
}
private void parseDigestAuthToken(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = protocolAddress.append(DigestAuthTokenResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH), operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case ALGORITHM: {
readAttribute(reader, i, operation, DigestAuthTokenResourceDefinition.Attribute.ALGORITHM);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseAuthTokenElement(reader, protocolAddress, operations);
}
require(reader, operation, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
}
private void parseCipherAuthToken(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = protocolAddress.append(CipherAuthTokenResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH), operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case KEY_ALIAS: {
readAttribute(reader, i, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_ALIAS);
break;
}
case KEY_STORE: {
readAttribute(reader, i, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_STORE);
break;
}
case ALGORITHM: {
readAttribute(reader, i, operation, CipherAuthTokenResourceDefinition.Attribute.ALGORITHM);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
require(reader, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_ALIAS, CipherAuthTokenResourceDefinition.Attribute.KEY_STORE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case KEY_CREDENTIAL_REFERENCE: {
readElement(reader, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_CREDENTIAL);
break;
}
default: {
this.parseAuthTokenElement(reader, protocolAddress, operations);
}
}
}
require(reader, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_CREDENTIAL, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
}
private void parseAuthTokenElement(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH));
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case SHARED_SECRET_CREDENTIAL_REFERENCE: {
readElement(reader, operation, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
private void parseProperty(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
ParseUtils.requireSingleAttribute(reader, XMLAttribute.NAME.getLocalName());
readElement(reader, operation, AbstractProtocolResourceDefinition.Attribute.PROPERTIES);
}
private void parseThreadPool(ThreadPoolResourceDefinition pool, XMLExtendedStreamReader reader, PathAddress parentAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = parentAddress.append(pool.getPathElement());
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case MIN_THREADS:
readAttribute(reader, i, operation, pool.getMinThreads());
break;
case MAX_THREADS:
readAttribute(reader, i, operation, pool.getMaxThreads());
break;
case QUEUE_LENGTH:
if (this.schema.since(JGroupsSubsystemSchema.VERSION_6_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
ClusteringLogger.ROOT_LOGGER.attributeIgnored(attribute.getLocalName(), reader.getLocalName());
break;
case KEEPALIVE_TIME:
readAttribute(reader, i, operation, pool.getKeepAliveTime());
break;
default:
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
ParseUtils.requireNoContent(reader);
}
private void parseRelay(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations, String defaultStack) throws XMLStreamException {
PathAddress address = stackAddress.append(RelayResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case SITE: {
readAttribute(reader, i, operation, RelayResourceDefinition.Attribute.SITE);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
require(reader, operation, RelayResourceDefinition.Attribute.SITE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case REMOTE_SITE: {
this.parseRemoteSite(reader, address, operations, defaultStack);
break;
}
case PROPERTY: {
this.parseProperty(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseRemoteSite(XMLExtendedStreamReader reader, PathAddress relayAddress, Map<PathAddress, ModelNode> operations, String defaultStack) throws XMLStreamException {
String site = require(reader, XMLAttribute.NAME);
PathAddress address = relayAddress.append(RemoteSiteResourceDefinition.pathElement(site));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
String cluster = null;
String stack = defaultStack;
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
case STACK: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
stack = reader.getAttributeValue(i);
break;
}
case CLUSTER: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
cluster = reader.getAttributeValue(i);
break;
}
case CHANNEL: {
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
readAttribute(reader, i, operation, RemoteSiteResourceDefinition.Attribute.CHANNEL);
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (this.schema.since(JGroupsSubsystemSchema.VERSION_3_0)) {
require(reader, operation, RemoteSiteResourceDefinition.Attribute.CHANNEL);
} else {
String channel = (cluster != null) ? cluster : site;
setAttribute(reader, channel, operation, RemoteSiteResourceDefinition.Attribute.CHANNEL);
// We need to create a corresponding channel add operation
PathAddress subsystemAddress = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
PathAddress channelAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement(channel));
ModelNode channelOperation = Util.createAddOperation(channelAddress);
setAttribute(reader, stack, channelOperation, ChannelResourceDefinition.Attribute.STACK);
operations.put(channelAddress, channelOperation);
}
ParseUtils.requireNoContent(reader);
}
private static String require(XMLExtendedStreamReader reader, XMLAttribute attribute) throws XMLStreamException {
String value = reader.getAttributeValue(null, attribute.getLocalName());
if (value == null) {
throw ParseUtils.missingRequired(reader, attribute.getLocalName());
}
return value;
}
private static void require(XMLExtendedStreamReader reader, ModelNode operation, Attribute... attributes) throws XMLStreamException {
for (Attribute attribute : attributes) {
if (!operation.hasDefined(attribute.getName())) {
AttributeDefinition definition = attribute.getDefinition();
Set<String> names = Collections.singleton(definition.getXmlName());
throw definition.getParser().isParseAsElement() ? ParseUtils.missingRequiredElement(reader, names) : ParseUtils.missingRequired(reader, names);
}
}
}
private static void readAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation, Attribute attribute) throws XMLStreamException {
setAttribute(reader, reader.getAttributeValue(index), operation, attribute);
}
private static void setAttribute(XMLExtendedStreamReader reader, String value, ModelNode operation, Attribute attribute) throws XMLStreamException {
attribute.getDefinition().getParser().parseAndSetParameter(attribute.getDefinition(), value, operation, reader);
}
private static void readElement(XMLExtendedStreamReader reader, ModelNode operation, Attribute attribute) throws XMLStreamException {
AttributeDefinition definition = attribute.getDefinition();
AttributeParser parser = definition.getParser();
if (parser.isParseAsElement()) {
parser.parseElement(definition, reader, operation);
} else {
parser.parseAndSetParameter(definition, reader.getElementText(), operation, reader);
}
}
}
| 44,164
| 44.86189
| 194
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/MulticastSocketProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.MulticastProtocolResourceDefinition.Attribute.SOCKET_BINDING;
import java.util.Map;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.SocketBinding;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jgroups.protocols.MPING;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* Custom builder for protocols that need to configure a multicast socket.
* @author Paul Ferraro
*/
public class MulticastSocketProtocolConfigurationServiceConfigurator extends ProtocolConfigurationServiceConfigurator<MPING> {
private volatile SupplierDependency<SocketBinding> binding;
public MulticastSocketProtocolConfigurationServiceConfigurator(PathAddress address) {
super(address);
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
return super.register(this.binding.register(builder));
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
String bindingName = SOCKET_BINDING.resolveModelAttribute(context, model).asString();
this.binding = new ServiceSupplierDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, bindingName));
return super.configure(context, model);
}
@Override
public Map<String, SocketBinding> getSocketBindings() {
SocketBinding binding = this.binding.get();
return Map.of("jgroups.mping.mcast_sock", binding, "jgroups.mping.mcast-send-sock", binding);
}
@Override
public void accept(MPING protocol) {
SocketBinding binding = this.binding.get();
protocol.setBindAddr(binding.getAddress());
protocol.setMcastAddr(binding.getMulticastAddress());
protocol.setMcastPort(binding.getMulticastPort());
}
}
| 3,285
| 40.594937
| 131
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemSchema.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.SubsystemSchema;
import org.jboss.as.controller.xml.VersionedNamespace;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.IntVersion;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Enumeration of the supported subsystem xml schemas.
* @author Paul Ferraro
*/
public enum JGroupsSubsystemSchema implements SubsystemSchema<JGroupsSubsystemSchema> {
VERSION_1_0(1, 0), // AS 7.0
VERSION_1_1(1, 1), // AS 7.1
VERSION_2_0(2, 0), // WildFly 8
VERSION_3_0(3, 0), // WildFly 9
VERSION_4_0(4, 0), // WildFly 10, EAP 7.0
VERSION_5_0(5, 0), // WildFly 11, EAP 7.1
VERSION_6_0(6, 0), // WildFly 12-16, EAP 7.2
VERSION_7_0(7, 0), // WildFly 17-19, EAP 7.3
VERSION_8_0(8, 0), // WildFly 20-26, EAP 7.4
VERSION_9_0(9, 0), // WildFly 27-present
;
static final JGroupsSubsystemSchema CURRENT = VERSION_9_0;
private final VersionedNamespace<IntVersion, JGroupsSubsystemSchema> namespace;
JGroupsSubsystemSchema(int major, int minor) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(JGroupsExtension.SUBSYSTEM_NAME, new IntVersion(major, minor));
}
@Override
public VersionedNamespace<IntVersion, JGroupsSubsystemSchema> getNamespace() {
return this.namespace;
}
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations) throws XMLStreamException {
new JGroupsSubsystemXMLReader(this).readElement(reader, operations);
}
}
| 2,664
| 37.623188
| 129
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/AbstractProtocolResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Consumer;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Base transformer for protocol/transport/relay resources.
* @author Paul Ferraro
*/
public class AbstractProtocolResourceTransformer implements Consumer<ModelVersion> {
final ResourceTransformationDescriptionBuilder builder;
AbstractProtocolResourceTransformer(ResourceTransformationDescriptionBuilder builder) {
this.builder = builder;
}
@Override
public void accept(ModelVersion version) {
// Nothing to transform
}
}
| 1,725
| 35.723404
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ThreadPoolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.Arrays;
import java.util.Collection;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.clustering.controller.ResourceDefinitionProvider;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.SimpleAttribute;
import org.jboss.as.clustering.controller.SimpleResourceRegistrar;
import org.jboss.as.clustering.controller.SimpleResourceServiceHandler;
import org.jboss.as.clustering.controller.validation.IntRangeValidatorBuilder;
import org.jboss.as.clustering.controller.validation.LongRangeValidatorBuilder;
import org.jboss.as.clustering.controller.validation.ParameterValidatorBuilder;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* @author Radoslav Husar
* @author Paul Ferraro
* @version Aug 2014
*/
public enum ThreadPoolResourceDefinition implements ResourceDefinitionProvider, ThreadPoolDefinition, ResourceServiceConfiguratorFactory {
DEFAULT("default", 0, 200, 0, 60000L),
;
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
private static PathElement pathElement(String name) {
return PathElement.pathElement("thread-pool", name);
}
private final PathElement path;
private final Attribute minThreads;
private final Attribute maxThreads;
private final Attribute keepAliveTime;
ThreadPoolResourceDefinition(String name, int defaultMinThreads, int defaultMaxThreads, int defaultQueueLength, long defaultKeepAliveTime) {
this.path = pathElement(name);
this.minThreads = new SimpleAttribute(createBuilder("min-threads", ModelType.INT, new ModelNode(defaultMinThreads), new IntRangeValidatorBuilder().min(0)).build());
this.maxThreads = new SimpleAttribute(createBuilder("max-threads", ModelType.INT, new ModelNode(defaultMaxThreads), new IntRangeValidatorBuilder().min(0)).build());
this.keepAliveTime = new SimpleAttribute(createBuilder("keepalive-time", ModelType.LONG, new ModelNode(defaultKeepAliveTime), new LongRangeValidatorBuilder().min(0)).build());
}
private static SimpleAttributeDefinitionBuilder createBuilder(String name, ModelType type, ModelNode defaultValue, ParameterValidatorBuilder validatorBuilder) {
SimpleAttributeDefinitionBuilder builder = new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(true)
.setRequired(false)
.setDefaultValue(defaultValue)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setMeasurementUnit((type == ModelType.LONG) ? MeasurementUnit.MILLISECONDS : null)
;
return builder.setValidator(validatorBuilder.configure(builder).build());
}
@Override
public void register(ManagementResourceRegistration parentRegistration) {
ResourceDescriptionResolver resolver = JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(this.path, pathElement(PathElement.WILDCARD_VALUE));
SimpleResourceDefinition.Parameters parameters = new SimpleResourceDefinition.Parameters(this.path, resolver);
ResourceDefinition definition = new SimpleResourceDefinition(parameters);
ManagementResourceRegistration registration = parentRegistration.registerSubModel(definition);
ResourceDescriptor descriptor = new ResourceDescriptor(resolver)
.addAttributes(this.minThreads, this.maxThreads, this.keepAliveTime)
;
ResourceServiceHandler handler = new SimpleResourceServiceHandler(this);
new SimpleResourceRegistrar(descriptor, handler).register(registration);
}
@Override
public ResourceServiceConfigurator createServiceConfigurator(PathAddress address) {
return new ThreadPoolFactoryServiceConfigurator(this, address);
}
Collection<Attribute> getAttributes() {
return Arrays.asList(this.minThreads, this.maxThreads, this.keepAliveTime);
}
@Override
public Attribute getMinThreads() {
return this.minThreads;
}
@Override
public Attribute getMaxThreads() {
return this.maxThreads;
}
@Override
public Attribute getKeepAliveTime() {
return this.keepAliveTime;
}
@Override
public PathElement getPathElement() {
return this.path;
}
}
| 6,178
| 45.458647
| 183
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.function.Consumer;
import org.jboss.as.clustering.jgroups.subsystem.ProtocolResourceRegistrar.AuthProtocol;
import org.jboss.as.clustering.jgroups.subsystem.ProtocolResourceRegistrar.EncryptProtocol;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transforms standard and override protocol resources registered via {@link ProtocolResourceRegistrar}.
* @author Paul Ferraro
*/
public class ProtocolTransformer implements Consumer<ModelVersion> {
private final Map<AuthProtocol, ResourceTransformationDescriptionBuilder> authBuilders = new EnumMap<>(AuthProtocol.class);
private final Map<EncryptProtocol, ResourceTransformationDescriptionBuilder> encryptBuilders = new EnumMap<>(EncryptProtocol.class);
ProtocolTransformer(ResourceTransformationDescriptionBuilder parent) {
for (AuthProtocol protocol : EnumSet.allOf(AuthProtocol.class)) {
this.authBuilders.put(protocol, parent.addChildResource(ProtocolResourceDefinition.pathElement(protocol.name())));
}
for (EncryptProtocol protocol : EnumSet.allOf(EncryptProtocol.class)) {
this.encryptBuilders.put(protocol, parent.addChildResource(ProtocolResourceDefinition.pathElement(protocol.name())));
}
}
@Override
public void accept(ModelVersion version) {
for (ResourceTransformationDescriptionBuilder builder : this.authBuilders.values()) {
new AuthProtocolResourceTransformer(builder).accept(version);
}
for (ResourceTransformationDescriptionBuilder builder : this.encryptBuilders.values()) {
new EncryptProtocolResourceTransformer(builder).accept(version);
}
}
}
| 2,926
| 45.460317
| 136
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.net.InetSocketAddress;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.management.MBeanServer;
import org.jboss.as.clustering.controller.Capability;
import org.jboss.as.clustering.controller.CapabilityServiceNameProvider;
import org.jboss.as.clustering.controller.CommonRequirement;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.jgroups.JChannel;
import org.jgroups.jmx.JmxConfigurator;
import org.jgroups.protocols.TP;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.clustering.service.AsyncServiceConfigurator;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.FunctionalService;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* Provides a connected channel for use by dependent services.
* @author Paul Ferraro
*/
public class ChannelServiceConfigurator extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, Supplier<JChannel>, Consumer<JChannel> {
private final String name;
private volatile SupplierDependency<ChannelFactory> factory;
private volatile SupplierDependency<MBeanServer> server;
private volatile SupplierDependency<String> cluster;
private volatile boolean statisticsEnabled = false;
public ChannelServiceConfigurator(Capability capability, PathAddress address) {
super(capability, address);
this.name = address.getLastElement().getValue();
}
public ChannelServiceConfigurator statisticsEnabled(boolean enabled) {
this.statisticsEnabled = enabled;
return this;
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = new AsyncServiceConfigurator(this.getServiceName()).build(target);
Consumer<JChannel> channel = new CompositeDependency(this.factory, this.cluster, this.server).register(builder).provides(this.getServiceName());
Service service = new FunctionalService<>(channel, Function.identity(), this, this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.cluster = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL_CLUSTER.getServiceName(context, this.name));
this.factory = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, this.name));
this.server = context.hasOptionalCapability(CommonRequirement.MBEAN_SERVER.getName(), null, null) ? new ServiceSupplierDependency<>(CommonRequirement.MBEAN_SERVER.getServiceName(context)) : null;
return this;
}
@Override
public JChannel get() {
try {
JChannel channel = this.factory.get().createChannel(this.name);
if (JGroupsLogger.ROOT_LOGGER.isTraceEnabled()) {
JGroupsLogger.ROOT_LOGGER.tracef("JGroups channel %s created with configuration:%n %s", this.name, channel.getProtocolStack().printProtocolSpec(true));
}
channel.stats(this.statisticsEnabled);
if (this.server != null) {
try {
JmxConfigurator.registerChannel(channel, this.server.get(), this.name);
} catch (Exception e) {
JGroupsLogger.ROOT_LOGGER.debug(e.getLocalizedMessage(), e);
}
}
String clusterName = this.cluster.get();
TP transport = channel.getProtocolStack().getTransport();
JGroupsLogger.ROOT_LOGGER.connecting(this.name, channel.getName(), clusterName, new InetSocketAddress(transport.getBindAddress(), transport.getBindPort()));
channel.connect(clusterName);
JGroupsLogger.ROOT_LOGGER.connected(this.name, channel.getName(), clusterName, channel.getView());
return channel;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
@Override
public void accept(JChannel channel) {
String clusterName = this.cluster.get();
JGroupsLogger.ROOT_LOGGER.disconnecting(this.name, channel.getName(), clusterName, channel.getView());
channel.disconnect();
JGroupsLogger.ROOT_LOGGER.disconnected(this.name, channel.getName(), clusterName);
if (this.server != null) {
try {
JmxConfigurator.unregisterChannel(channel, this.server.get(), this.name);
} catch (Exception e) {
JGroupsLogger.ROOT_LOGGER.debug(e.getLocalizedMessage(), e);
}
}
channel.close();
}
}
| 6,470
| 43.9375
| 203
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemModel.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.SubsystemModel;
/**
* Enumerates the supported model versions.
* @author Paul Ferraro
*/
public enum JGroupsSubsystemModel implements SubsystemModel {
/* Unsupported model versions - for reference only
VERSION_1_3_0(1, 3, 0), // EAP 6.4
VERSION_2_0_0(2, 0, 0), // WildFly 8
VERSION_3_0_0(3, 0, 0), // WildFly 9
VERSION_4_0_0(4, 0, 0), // WildFly 10, EAP 7.0
VERSION_4_1_0(4, 1, 0), // WildFly 10.1
*/ // We will continue to support generic protocol resource definition overrides
VERSION_5_0_0(5, 0, 0), // WildFly 11, EAP 7.1
/*
VERSION_6_0_0(6, 0, 0), // WildFly 12-16, EAP 7.2
VERSION_7_0_0(7, 0, 0), // WildFly 17-19, EAP 7.3
*/
VERSION_8_0_0(8, 0, 0), // WildFly 20-26, EAP 7.4
VERSION_9_0_0(9, 0, 0), // WildFly 27-present
;
static final JGroupsSubsystemModel CURRENT = VERSION_9_0_0;
private final ModelVersion version;
JGroupsSubsystemModel(int major, int minor, int micro) {
this.version = ModelVersion.create(major, minor, micro);
}
@Override
public ModelVersion getVersion() {
return this.version;
}
}
| 2,260
| 36.683333
| 81
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.Function;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescription;
import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder;
/**
* Transformer for the JGroups subsystem resource.
* @author Paul Ferraro
*/
public class JGroupsSubsystemResourceTransformer implements Function<ModelVersion, TransformationDescription> {
private final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
@Override
public TransformationDescription apply(ModelVersion version) {
ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
new ChannelResourceTransformer(this.builder).accept(version);
return builder.build();
}
}
| 2,075
| 41.367347
| 136
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/EncryptProtocolResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.jgroups.subsystem.EncryptProtocolResourceDefinition.Attribute;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.security.CredentialReference;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for encrypt protocol resources.
* @author Paul Ferraro
*/
public class EncryptProtocolResourceTransformer extends ProtocolResourceTransformer {
EncryptProtocolResourceTransformer(ResourceTransformationDescriptionBuilder builder) {
super(builder);
}
@Override
public void accept(ModelVersion version) {
if (JGroupsSubsystemModel.VERSION_8_0_0.requiresTransformation(version)) {
this.builder.getAttributeBuilder()
.addRejectCheck(CredentialReference.REJECT_CREDENTIAL_REFERENCE_WITH_BOTH_STORE_AND_CLEAR_TEXT, Attribute.KEY_CREDENTIAL.getName())
.end();
}
super.accept(version);
}
}
| 2,082
| 39.057692
| 151
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsExtension.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.controller.SubsystemExtension;
import org.jboss.as.clustering.jgroups.LogFactory;
import org.jboss.as.controller.Extension;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver;
import org.kohsuke.MetaInfServices;
/**
* Registers the JGroups subsystem.
*
* @author Paul Ferraro
* @author Richard Achmatowicz (c) 2011 Red Hat Inc.
*/
@MetaInfServices(Extension.class)
public class JGroupsExtension extends SubsystemExtension<JGroupsSubsystemSchema> {
static final String SUBSYSTEM_NAME = "jgroups";
static final ParentResourceDescriptionResolver SUBSYSTEM_RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME, JGroupsExtension.class);
public JGroupsExtension() {
super(SUBSYSTEM_NAME, JGroupsSubsystemModel.CURRENT, JGroupsSubsystemResourceDefinition::new, JGroupsSubsystemSchema.CURRENT, new JGroupsSubsystemXMLWriter());
// Workaround for JGRP-1475
// Configure JGroups to use jboss-logging.
org.jgroups.logging.LogFactory.setCustomLogFactory(new LogFactory());
}
}
| 2,251
| 43.156863
| 167
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelMetric.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.controller.Metric;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jgroups.JChannel;
/**
* Enumerates management metrics for a channel.
* @author Paul Ferraro
*/
public enum ChannelMetric implements Metric<JChannel> {
ADDRESS("address", ModelType.STRING) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getAddressAsString());
}
},
ADDRESS_AS_UUID("address-as-uuid", ModelType.STRING) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getAddressAsUUID());
}
},
DISCARD_OWN_MESSAGES("discard-own-messages", ModelType.BOOLEAN) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getDiscardOwnMessages());
}
},
RECEIVED_BYTES("received-bytes", ModelType.LONG) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getProtocolStack().getTransport().getMessageStats().getNumBytesReceived());
}
},
RECEIVED_MESSAGES("received-messages", ModelType.LONG) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getProtocolStack().getTransport().getMessageStats().getNumMsgsReceived());
}
},
SENT_BYTES("sent-bytes", ModelType.LONG) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getProtocolStack().getTransport().getMessageStats().getNumBytesSent());
}
},
SENT_MESSAGES("sent-messages", ModelType.LONG) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getProtocolStack().getTransport().getMessageStats().getNumMsgsSent());
}
},
STATE("state", ModelType.STRING) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getState());
}
},
VERSION("version", ModelType.STRING) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(JChannel.getVersion());
}
},
VIEW("view", ModelType.STRING) {
@Override
public ModelNode execute(JChannel channel) {
return new ModelNode(channel.getViewAsString());
}
},
;
private final AttributeDefinition definition;
ChannelMetric(String name, ModelType type) {
this(name, type, null);
}
ChannelMetric(String name, ModelType type, JGroupsSubsystemModel deprecation) {
SimpleAttributeDefinitionBuilder builder = new SimpleAttributeDefinitionBuilder(name, type, true).setStorageRuntime();
if (deprecation != null) {
builder.setDeprecated(deprecation.getVersion());
}
this.definition = builder.build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
| 4,298
| 35.74359
| 126
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JChannelFactoryServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jboss.as.clustering.controller.CapabilityServiceNameProvider;
import org.jboss.as.clustering.controller.CommonRequirement;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.jgroups.JChannelFactory;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.network.SocketBindingManager;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerEnvironmentService;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.jgroups.protocols.TP;
import org.jgroups.stack.Protocol;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;
import org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration;
import org.wildfly.clustering.jgroups.spi.RelayConfiguration;
import org.wildfly.clustering.jgroups.spi.TransportConfiguration;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* Builder for a service that provides a {@link ChannelFactory} for creating channels.
* @author Paul Ferraro
*/
public class JChannelFactoryServiceConfigurator extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, ProtocolStackConfiguration {
private final PathAddress address;
private volatile boolean statisticsEnabled;
private volatile SupplierDependency<TransportConfiguration<? extends TP>> transport = null;
private volatile List<SupplierDependency<ProtocolConfiguration<? extends Protocol>>> protocols = null;
private volatile SupplierDependency<RelayConfiguration> relay = null;
private volatile SupplierDependency<SocketBindingManager> socketBindingManager;
private volatile Supplier<ServerEnvironment> environment;
public JChannelFactoryServiceConfigurator(PathAddress address) {
super(StackResourceDefinition.Capability.JCHANNEL_FACTORY, address);
this.address = address;
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<ChannelFactory> factory = new CompositeDependency(this.transport, this.relay, this.socketBindingManager).register(builder).provides(this.getServiceName());
this.environment = builder.requires(ServerEnvironmentService.SERVICE_NAME);
for (Dependency dependency : this.protocols) {
dependency.register(builder);
}
Service service = Service.newInstance(factory, new JChannelFactory(this));
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.statisticsEnabled = StackResourceDefinition.Attribute.STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
Resource resource = context.readResourceFromRoot(this.address, false);
Iterator<Resource.ResourceEntry> transports = resource.getChildren(TransportResourceDefinition.WILDCARD_PATH.getKey()).iterator();
if (!transports.hasNext()) {
throw JGroupsLogger.ROOT_LOGGER.transportNotDefined(this.getName());
}
this.transport = new ServiceSupplierDependency<>(new SingletonProtocolServiceNameProvider(this.address, transports.next().getPathElement()));
Set<Resource.ResourceEntry> entries = resource.getChildren(ProtocolResourceDefinition.WILDCARD_PATH.getKey());
this.protocols = new ArrayList<>(entries.size());
for (Resource.ResourceEntry entry : entries) {
this.protocols.add(new ServiceSupplierDependency<>(new ProtocolServiceNameProvider(this.address, entry.getPathElement())));
}
this.relay = resource.hasChild(RelayResourceDefinition.PATH) ? new ServiceSupplierDependency<>(new SingletonProtocolServiceNameProvider(this.address, RelayResourceDefinition.PATH)) : null;
this.socketBindingManager = new ServiceSupplierDependency<>(CommonRequirement.SOCKET_BINDING_MANAGER.getServiceName(context));
return this;
}
@Override
public String getName() {
return this.address.getLastElement().getValue();
}
@Override
public TransportConfiguration<? extends TP> getTransport() {
return this.transport.get();
}
@Override
public List<ProtocolConfiguration<? extends Protocol>> getProtocols() {
List<ProtocolConfiguration<? extends Protocol>> protocols = new ArrayList<>(this.protocols.size());
for (Supplier<ProtocolConfiguration<? extends Protocol>> protocolValue : this.protocols) {
ProtocolConfiguration<? extends Protocol> protocol = protocolValue.get();
protocols.add(protocol);
}
return protocols;
}
@Override
public String getNodeName() {
return this.environment.get().getNodeName();
}
@Override
public Optional<RelayConfiguration> getRelay() {
return (this.relay != null) ? Optional.of(this.relay.get()) : Optional.empty();
}
@Override
public boolean isStatisticsEnabled() {
return this.statisticsEnabled;
}
@Override
public SocketBindingManager getSocketBindingManager() {
return this.socketBindingManager.get();
}
}
| 7,204
| 44.314465
| 196
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/SocketTransportResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.SimpleResourceDescriptorConfigurator;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelType;
/**
* @author Paul Ferraro
*/
public class SocketTransportResourceDefinition extends TransportResourceDefinition {
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
CLIENT_SOCKET_BINDING("client-socket-binding", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder
.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.setCapabilityReference(new CapabilityReference(Capability.TRANSPORT, CommonUnaryRequirement.SOCKET_BINDING));
}
},
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(false)
.setRequired(false)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder;
}
}
SocketTransportResourceDefinition(String name, ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(pathElement(name), new SimpleResourceDescriptorConfigurator<>(Attribute.class), serviceConfiguratorFactory, parentServiceConfiguratorFactory);
}
}
| 3,486
| 44.285714
| 184
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ForkProtocolRuntimeResourceRegistration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.RuntimeResourceRegistration;
import org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.Attribute;
import org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.FieldType;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.OverrideDescriptionProvider;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
import org.jgroups.JChannel;
import org.jgroups.stack.Protocol;
/**
* Operation handler for registration of fork protocol runtime resources.
* @author Paul Ferraro
*/
public class ForkProtocolRuntimeResourceRegistration implements RuntimeResourceRegistration {
private final FunctionExecutorRegistry<JChannel> executors;
public ForkProtocolRuntimeResourceRegistration(FunctionExecutorRegistry<JChannel> executors) {
this.executors = executors;
}
@Override
public void register(OperationContext context) throws OperationFailedException {
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate();
String protocolName = context.getCurrentAddressValue();
String moduleName = ProtocolResourceDefinition.Attribute.MODULE.resolveModelAttribute(context, resource.getModel()).asString();
Class<? extends Protocol> protocolClass = ChannelRuntimeResourceRegistration.findProtocolClass(context, protocolName, moduleName);
Map<String, Attribute> attributes = ProtocolMetricsHandler.findProtocolAttributes(protocolClass);
// If this is a wildcard registration, create an override model registration with which to register protocol-specific metrics
if (registration.getPathAddress().getLastElement().isWildcard()) {
OverrideDescriptionProvider provider = new OverrideDescriptionProvider() {
@Override
public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
Map<String, ModelNode> result = new HashMap<>();
for (Attribute attribute : attributes.values()) {
ModelNode value = new ModelNode();
value.get(ModelDescriptionConstants.DESCRIPTION).set(attribute.getDescription());
result.put(attribute.getName(), value);
}
return result;
}
@Override
public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
return Collections.emptyMap();
}
};
registration = registration.registerOverrideModel(protocolName, provider);
}
ProtocolMetricsHandler handler = new ProtocolMetricsHandler(this.executors);
for (Attribute attribute : attributes.values()) {
String name = attribute.getName();
FieldType type = FieldType.valueOf(attribute.getType());
registration.registerMetric(new SimpleAttributeDefinitionBuilder(name, type.getModelType()).setStorageRuntime().build(), handler);
}
}
@Override
public void unregister(OperationContext context) throws OperationFailedException {
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate();
String protocolName = context.getCurrentAddressValue();
String moduleName = ProtocolResourceDefinition.Attribute.MODULE.resolveModelAttribute(context, resource.getModel()).asString();
Class<? extends Protocol> protocolClass = ChannelRuntimeResourceRegistration.findProtocolClass(context, protocolName, moduleName);
for (String attribute : ProtocolMetricsHandler.findProtocolAttributes(protocolClass).keySet()) {
registration.unregisterAttribute(attribute);
}
}
}
| 5,575
| 48.345133
| 142
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ThreadPoolDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.controller.Attribute;
/**
* @author Paul Ferraro
*/
public interface ThreadPoolDefinition {
Attribute getMinThreads();
Attribute getMaxThreads();
Attribute getKeepAliveTime();
}
| 1,300
| 36.171429
| 70
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ForkServiceHandler.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.ForkResourceDefinition.Capability.FORK_CHANNEL;
import static org.jboss.as.clustering.jgroups.subsystem.ForkResourceDefinition.Capability.FORK_CHANNEL_CLUSTER;
import static org.jboss.as.clustering.jgroups.subsystem.ForkResourceDefinition.Capability.FORK_CHANNEL_FACTORY;
import static org.jboss.as.clustering.jgroups.subsystem.ForkResourceDefinition.Capability.FORK_CHANNEL_MODULE;
import static org.jboss.as.clustering.jgroups.subsystem.ForkResourceDefinition.Capability.FORK_CHANNEL_SOURCE;
import java.util.EnumSet;
import org.jboss.as.clustering.controller.Capability;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.SimpleResourceServiceHandler;
import org.jboss.as.clustering.naming.BinderServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.clustering.server.service.ProvidedIdentityGroupServiceConfigurator;
import org.wildfly.clustering.service.IdentityServiceConfigurator;
/**
* @author Paul Ferraro
*/
public class ForkServiceHandler extends SimpleResourceServiceHandler {
ForkServiceHandler(ResourceServiceConfiguratorFactory factory) {
super(factory);
}
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
super.installServices(context, model);
PathAddress address = context.getCurrentAddress();
String name = address.getLastElement().getValue();
String channel = address.getParent().getLastElement().getValue();
ServiceTarget target = context.getServiceTarget();
new IdentityServiceConfigurator<>(FORK_CHANNEL_SOURCE.getServiceName(address), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, channel)).build(target).install();
new IdentityServiceConfigurator<>(FORK_CHANNEL_MODULE.getServiceName(address), JGroupsRequirement.CHANNEL_MODULE.getServiceName(context, channel)).build(target).install();
new IdentityServiceConfigurator<>(FORK_CHANNEL_CLUSTER.getServiceName(address), JGroupsRequirement.CHANNEL_CLUSTER.getServiceName(context, channel)).build(target).install();
new ChannelServiceConfigurator(FORK_CHANNEL, address).configure(context, model).build(target).install();
new BinderServiceConfigurator(JGroupsBindingFactory.createChannelBinding(name), JGroupsRequirement.CHANNEL.getServiceName(context, name)).build(target).install();
new BinderServiceConfigurator(JGroupsBindingFactory.createChannelFactoryBinding(name), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, name)).build(target).install();
new ProvidedIdentityGroupServiceConfigurator(name, channel).configure(context).build(target).install();
}
@Override
public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
String name = context.getCurrentAddressValue();
String channel = address.getParent().getLastElement().getValue();
new ProvidedIdentityGroupServiceConfigurator(name, channel).remove(context);
context.removeService(JGroupsBindingFactory.createChannelBinding(name).getBinderServiceName());
context.removeService(JGroupsBindingFactory.createChannelFactoryBinding(name).getBinderServiceName());
// FORK_CHANNEL_FACTORY is removed by super impl
for (Capability capability : EnumSet.complementOf(EnumSet.of(FORK_CHANNEL_FACTORY))) {
context.removeService(capability.getServiceName(address));
}
super.removeServices(context, model);
}
}
| 5,032
| 50.886598
| 185
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ForkChannelFactoryServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jboss.as.clustering.controller.Capability;
import org.jboss.as.clustering.controller.CapabilityServiceNameProvider;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.jgroups.ForkChannelFactory;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.PlaceholderResource;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.jgroups.JChannel;
import org.jgroups.protocols.FORK;
import org.jgroups.stack.Protocol;
import org.jgroups.stack.ProtocolStack;
import org.wildfly.clustering.jgroups.spi.ChannelFactory;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.clustering.jgroups.spi.ProtocolConfiguration;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.FunctionalService;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* Builder for a service that provides a {@link ChannelFactory} for creating fork channels.
* @author Paul Ferraro
*/
public class ForkChannelFactoryServiceConfigurator extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, Supplier<ChannelFactory>, Consumer<ChannelFactory> {
private final PathAddress address;
private volatile List<SupplierDependency<ProtocolConfiguration<? extends Protocol>>> protocols;
private volatile SupplierDependency<JChannel> parentChannel;
private volatile SupplierDependency<ChannelFactory> parentFactory;
public ForkChannelFactoryServiceConfigurator(Capability capability, PathAddress address) {
super(capability, address);
this.address = address;
}
@Override
public ChannelFactory get() {
List<ProtocolConfiguration<? extends Protocol>> protocols = new ArrayList<>(this.protocols.size());
for (Supplier<ProtocolConfiguration<? extends Protocol>> protocolDependency : this.protocols) {
protocols.add(protocolDependency.get());
}
return new ForkChannelFactory(this.parentChannel.get(), this.parentFactory.get(), protocols);
}
@Override
public void accept(ChannelFactory factory) {
ProtocolStack stack = this.parentChannel.get().getProtocolStack();
FORK fork = (FORK) stack.findProtocol(FORK.class);
fork.remove(this.address.getLastElement().getValue());
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<ChannelFactory> factory = new CompositeDependency(this.parentChannel, this.parentFactory).register(builder).provides(this.getServiceName());
for (Dependency dependency : this.protocols) {
dependency.register(builder);
}
Service service = new FunctionalService<>(factory, Function.identity(), this, this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.PASSIVE);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
Resource resource = context.getCurrentAddress().equals(this.address) ? context.readResourceFromRoot(this.address, false) : PlaceholderResource.INSTANCE;
Set<Resource.ResourceEntry> entries = resource.getChildren(ProtocolResourceDefinition.WILDCARD_PATH.getKey());
this.protocols = new ArrayList<>(entries.size());
for (Resource.ResourceEntry entry : entries) {
this.protocols.add(new ServiceSupplierDependency<>(new ProtocolServiceNameProvider(this.address, entry.getPathElement())));
}
String channelName = this.address.getParent().getLastElement().getValue();
this.parentChannel = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL.getServiceName(context, channelName));
this.parentFactory = new ServiceSupplierDependency<>(JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, channelName));
return this;
}
}
| 5,751
| 48.586207
| 181
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/MulticastTransportConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.SocketBinding;
import org.jgroups.protocols.UDP;
/**
* Custom builder for transports that need to configure a multicast socket.
* @author Paul Ferraro
*/
public class MulticastTransportConfigurationServiceConfigurator extends TransportConfigurationServiceConfigurator<UDP> {
public MulticastTransportConfigurationServiceConfigurator(PathAddress address) {
super(address);
}
@Override
public void accept(UDP protocol) {
SocketBinding binding = this.getSocketBinding();
protocol.setMulticasting(binding.getMulticastAddress() != null);
if (protocol.supportsMulticasting()) {
protocol.setMulticastAddress(binding.getMulticastAddress());
protocol.setMulticastPort(binding.getMulticastPort());
}
super.accept(protocol);
}
}
| 1,964
| 38.3
| 120
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ThreadPoolConfiguration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
/**
* @author Paul Ferraro
*/
public interface ThreadPoolConfiguration {
int getMinThreads();
int getMaxThreads();
long getKeepAliveTime();
}
| 1,232
| 36.363636
| 70
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/DigestAuthTokenResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for digest auth token resources.
* @author Paul Ferraro
*/
public class DigestAuthTokenResourceTransformer extends AuthTokenResourceTransformer {
DigestAuthTokenResourceTransformer(ResourceTransformationDescriptionBuilder parent) {
super(parent.addChildResource(DigestAuthTokenResourceDefinition.PATH));
}
}
| 1,518
| 40.054054
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolMetricsHandler.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
import org.jboss.as.clustering.controller.FunctionExecutor;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.AbstractRuntimeOnlyHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.ServiceName;
import org.jgroups.JChannel;
import org.jgroups.annotations.ManagedAttribute;
import org.jgroups.annotations.Property;
import org.jgroups.stack.Protocol;
import org.jgroups.util.Util;
import org.wildfly.clustering.jgroups.spi.JGroupsRequirement;
import org.wildfly.common.function.ExceptionFunction;
/**
* A generic handler for protocol metrics based on reflection.
*
* @author Richard Achmatowicz (c) 2013 Red Hat Inc.
* @author Radoslav Husar
* @author Paul Ferraro
*/
public class ProtocolMetricsHandler extends AbstractRuntimeOnlyHandler {
interface Attribute {
String getName();
String getDescription();
Class<?> getType();
Object read(Object object) throws Exception;
}
abstract static class AbstractAttribute<A extends AccessibleObject> implements Attribute {
final A accessible;
AbstractAttribute(A accessible) {
this.accessible = accessible;
}
@Override
public String getName() {
if (this.accessible.isAnnotationPresent(ManagedAttribute.class)) {
String name = this.accessible.getAnnotation(ManagedAttribute.class).name();
if (!name.isEmpty()) return name;
}
if (this.accessible.isAnnotationPresent(Property.class)) {
String name = this.accessible.getAnnotation(Property.class).name();
if (!name.isEmpty()) return name;
}
return null;
}
@Override
public String getDescription() {
if (this.accessible.isAnnotationPresent(ManagedAttribute.class)) {
return this.accessible.getAnnotation(ManagedAttribute.class).description();
}
if (this.accessible.isAnnotationPresent(Property.class)) {
return this.accessible.getAnnotation(Property.class).description();
}
return this.accessible.toString();
}
@Override
public Object read(final Object object) throws Exception {
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<>() {
@Override
public Object run() throws Exception {
AbstractAttribute.this.accessible.setAccessible(true);
try {
return AbstractAttribute.this.get(object);
} finally {
AbstractAttribute.this.accessible.setAccessible(false);
}
}
};
try {
return AccessController.doPrivileged(action);
} catch (PrivilegedActionException e) {
throw e.getException();
}
}
abstract Object get(Object object) throws Exception;
}
static class FieldAttribute extends AbstractAttribute<Field> {
FieldAttribute(Field field) {
super(field);
}
@Override
public String getName() {
String name = super.getName();
return (name != null) ? name : this.accessible.getName();
}
@Override
public Class<?> getType() {
return this.accessible.getType();
}
@Override
Object get(Object object) throws IllegalAccessException {
return this.accessible.get(object);
}
}
static class MethodAttribute extends AbstractAttribute<Method> {
MethodAttribute(Method method) {
super(method);
}
@Override
public String getName() {
String name = super.getName();
return (name != null) ? name : Util.methodNameToAttributeName(this.accessible.getName());
}
@Override
public Class<?> getType() {
return this.accessible.getReturnType();
}
@Override
Object get(Object object) throws IllegalAccessException, InvocationTargetException {
return this.accessible.invoke(object);
}
}
enum FieldType {
BOOLEAN(ModelType.BOOLEAN, Boolean.TYPE, Boolean.class) {
@Override
void setValue(ModelNode node, Object value) {
node.set((Boolean) value);
}
},
INT(ModelType.INT, Integer.TYPE, Integer.class, Byte.TYPE, Byte.class, Short.TYPE, Short.class) {
@Override
void setValue(ModelNode node, Object value) {
node.set(((Number) value).intValue());
}
},
LONG(ModelType.LONG, Long.TYPE, Long.class) {
@Override
void setValue(ModelNode node, Object value) {
node.set((Long) value);
}
},
DOUBLE(ModelType.DOUBLE, Double.TYPE, Double.class, Float.TYPE, Float.class) {
@Override
void setValue(ModelNode node, Object value) {
node.set(((Number) value).doubleValue());
}
},
STRING(ModelType.STRING) {
@Override
void setValue(ModelNode node, Object value) {
node.set(value.toString());
}
},
;
private static final Map<Class<?>, FieldType> TYPES = new HashMap<>();
static {
for (FieldType type : FieldType.values()) {
for (Class<?> classType : type.types) {
TYPES.put(classType, type);
}
}
}
private final Class<?>[] types;
private final ModelType modelType;
FieldType(ModelType modelType, Class<?>... types) {
this.modelType = modelType;
this.types = types;
}
abstract void setValue(ModelNode node, Object value);
public ModelType getModelType() {
return this.modelType;
}
public static FieldType valueOf(Class<?> typeClass) {
FieldType type = TYPES.get(typeClass);
return (type != null) ? type : STRING;
}
}
private final FunctionExecutorRegistry<JChannel> executors;
public ProtocolMetricsHandler(FunctionExecutorRegistry<JChannel> executors) {
this.executors = executors;
}
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
String name = operation.get(ModelDescriptionConstants.NAME).asString();
String protocolName = context.getCurrentAddressValue();
ServiceName channelServiceName = JGroupsRequirement.CHANNEL.getServiceName(context, UnaryCapabilityNameResolver.PARENT);
ExceptionFunction<JChannel, ModelNode, Exception> function = new ExceptionFunction<>() {
@Override
public ModelNode apply(JChannel channel) throws Exception {
int index = protocolName.lastIndexOf('.');
Protocol protocol = channel.getProtocolStack().findProtocol((index < 0) ? protocolName : protocolName.substring(index + 1));
if (protocol == null) {
throw new IllegalArgumentException(protocolName);
}
Attribute attribute = getAttribute(protocol.getClass(), name);
if (attribute == null) {
throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.unknownMetric(name));
}
FieldType type = FieldType.valueOf(attribute.getType());
ModelNode result = new ModelNode();
Object value = attribute.read(protocol);
if (value != null) {
type.setValue(result, value);
}
return result;
}
};
FunctionExecutor<JChannel> executor = this.executors.get(channelServiceName);
try {
ModelNode value = (executor != null) ? executor.execute(function) : null;
if (value != null) {
context.getResult().set(value);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
} finally {
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}
static Attribute getAttribute(Class<? extends Protocol> targetClass, String name) {
Map<String, Attribute> attributes = findProtocolAttributes(targetClass);
return attributes.get(name);
}
static Map<String, Attribute> findProtocolAttributes(Class<? extends Protocol> protocolClass) {
Map<String, Attribute> attributes = new HashMap<>();
Class<?> targetClass = protocolClass;
while (Protocol.class.isAssignableFrom(targetClass)) {
for (Method method: targetClass.getDeclaredMethods()) {
if ((method.getParameterCount() == 0) && isManagedAttribute(method)) {
putIfAbsent(attributes, new MethodAttribute(method));
}
}
for (Field field: targetClass.getDeclaredFields()) {
if (isManagedAttribute(field)) {
putIfAbsent(attributes, new FieldAttribute(field));
}
}
targetClass = targetClass.getSuperclass();
}
return attributes;
}
private static void putIfAbsent(Map<String, Attribute> attributes, Attribute attribute) {
// Some of JGroups @Property-s use '.' in their names (e.g. "timer.queue_max_size") which is disallowed in the domain model,
// thus we replace all with '-' since JGroups never uses them and this mapping is bijective.
String name = attribute.getName().replace('.', '-');
if (!attributes.containsKey(name)) {
attributes.put(name, attribute);
}
}
private static boolean isManagedAttribute(AccessibleObject object) {
return object.isAnnotationPresent(ManagedAttribute.class) || (object.isAnnotationPresent(Property.class) && object.getAnnotation(Property.class).exposeAsManagedAttribute());
}
}
| 12,099
| 37.782051
| 181
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/SocketDiscoveryProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.SocketDiscoveryProtocolResourceDefinition.Attribute.OUTBOUND_SOCKET_BINDINGS;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.jgroups.logging.JGroupsLogger;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.StringListAttributeDefinition;
import org.jboss.as.network.OutboundSocketBinding;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jgroups.protocols.Discovery;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* @author Paul Ferraro
*/
public class SocketDiscoveryProtocolConfigurationServiceConfigurator<A, P extends Discovery> extends ProtocolConfigurationServiceConfigurator<P> {
private final Function<InetSocketAddress, A> hostTransformer;
private final List<SupplierDependency<OutboundSocketBinding>> bindings = new LinkedList<>();
public SocketDiscoveryProtocolConfigurationServiceConfigurator(PathAddress address, Function<InetSocketAddress, A> hostTransformer) {
super(address);
this.hostTransformer = hostTransformer;
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.bindings.clear();
for (String binding : StringListAttributeDefinition.unwrapValue(context, OUTBOUND_SOCKET_BINDINGS.resolveModelAttribute(context, model))) {
this.bindings.add(new ServiceSupplierDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, binding)));
}
return super.configure(context, model);
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
for (Dependency dependency : this.bindings) {
dependency.register(builder);
}
return super.register(builder);
}
@Override
public void accept(P protocol) {
if (!this.bindings.isEmpty()) {
List<A> initialHosts = new ArrayList<>(this.bindings.size());
for (Supplier<OutboundSocketBinding> bindingValue : this.bindings) {
OutboundSocketBinding binding = bindingValue.get();
try {
initialHosts.add(this.hostTransformer.apply(new InetSocketAddress(binding.getResolvedDestinationAddress(), binding.getDestinationPort())));
} catch (UnknownHostException e) {
throw JGroupsLogger.ROOT_LOGGER.failedToResolveSocketBinding(e, binding);
}
}
// In the absence of some common interface, we need to use reflection
this.setValue(protocol, "initial_hosts", initialHosts);
}
}
}
| 4,339
| 43.742268
| 159
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/SocketProtocolConfigurationServiceConfigurator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import static org.jboss.as.clustering.jgroups.subsystem.SocketProtocolResourceDefinition.Attribute.CLIENT_SOCKET_BINDING;
import static org.jboss.as.clustering.jgroups.subsystem.SocketProtocolResourceDefinition.Attribute.SOCKET_BINDING;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.SocketBinding;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
import org.jgroups.protocols.TP;
import org.jgroups.stack.Protocol;
import org.wildfly.clustering.jgroups.spi.TransportConfiguration;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SimpleSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
/**
* Configures a service that provides a FD_SOCK protocol.
* @author Paul Ferraro
*/
public abstract class SocketProtocolConfigurationServiceConfigurator<P extends Protocol> extends ProtocolConfigurationServiceConfigurator<P> {
private volatile SupplierDependency<SocketBinding> binding;
private volatile SupplierDependency<SocketBinding> clientBinding;
private final SupplierDependency<TransportConfiguration<? extends TP>> transport;
public SocketProtocolConfigurationServiceConfigurator(PathAddress address) {
super(address);
this.transport = new ServiceSupplierDependency<>(new SingletonProtocolServiceNameProvider(address.getParent(), TransportResourceDefinition.WILDCARD_PATH));
}
@Override
public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) {
return super.register(new CompositeDependency(this.binding, this.clientBinding, this.transport).register(builder));
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.binding = createDependency(context, model, SOCKET_BINDING);
this.clientBinding = createDependency(context, model, CLIENT_SOCKET_BINDING);
return super.configure(context, model);
}
private static SupplierDependency<SocketBinding> createDependency(OperationContext context, ModelNode model, Attribute attribute) throws OperationFailedException {
String bindingName = attribute.resolveModelAttribute(context, model).asStringOrNull();
return (bindingName != null) ? new ServiceSupplierDependency<>(CommonUnaryRequirement.SOCKET_BINDING.getServiceName(context, bindingName)) : new SimpleSupplierDependency<>(null);
}
SocketBinding getSocketBinding() {
return this.binding.get();
}
SocketBinding getClientSocketBinding() {
return this.clientBinding.get();
}
TransportConfiguration<? extends TP> getTransport() {
return this.transport.get();
}
}
| 4,170
| 45.865169
| 186
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/PlainAuthTokenResourceTransformer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transformer for plain auth token resources.
* @author Paul Ferraro
*/
public class PlainAuthTokenResourceTransformer extends AuthTokenResourceTransformer {
PlainAuthTokenResourceTransformer(ResourceTransformationDescriptionBuilder parent) {
super(parent.addChildResource(PlainAuthTokenResourceDefinition.PATH));
}
}
| 1,514
| 39.945946
| 94
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/DigestAuthTokenResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import org.jboss.as.clustering.controller.SimpleResourceDescriptorConfigurator;
import org.jboss.as.clustering.jgroups.auth.BinaryAuthToken;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* @author Paul Ferraro
*/
public class DigestAuthTokenResourceDefinition extends AuthTokenResourceDefinition<BinaryAuthToken> {
static final PathElement PATH = pathElement("digest");
enum Attribute implements org.jboss.as.clustering.controller.Attribute {
ALGORITHM("algorithm", ModelType.STRING, new ModelNode("SHA-256")),
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type, ModelNode defaultValue) {
this.definition = new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(true)
.setDefaultValue(defaultValue)
.setRequired(false)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
DigestAuthTokenResourceDefinition() {
super(PATH, new SimpleResourceDescriptorConfigurator<>(Attribute.class), DigestAuthTokenServiceConfigurator::new);
}
}
| 2,618
| 39.292308
| 122
|
java
|
null |
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/SocketProtocolResourceDefinition.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelType;
/**
* Resource definition override for protocols that have an optional socket-binding.
* @author Paul Ferraro
*/
public class SocketProtocolResourceDefinition extends ProtocolResourceDefinition {
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
SOCKET_BINDING(ModelDescriptionConstants.SOCKET_BINDING, ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.setCapabilityReference(new CapabilityReference(Capability.PROTOCOL, CommonUnaryRequirement.SOCKET_BINDING))
;
}
},
CLIENT_SOCKET_BINDING("client-socket-binding", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SOCKET_BINDING_REF)
.setCapabilityReference(new CapabilityReference(Capability.PROTOCOL, CommonUnaryRequirement.SOCKET_BINDING))
;
}
},
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setRequired(false)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
).build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> {
private final UnaryOperator<ResourceDescriptor> configurator;
ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) {
this.configurator = configurator;
}
@Override
public ResourceDescriptor apply(ResourceDescriptor descriptor) {
return this.configurator.apply(descriptor).addAttributes(Attribute.class);
}
}
SocketProtocolResourceDefinition(String name, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) {
super(pathElement(name), new ResourceDescriptorConfigurator(configurator), serviceConfiguratorFactory, parentServiceConfiguratorFactory);
}
}
| 4,476
| 46.62766
| 231
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.