Overridden version, potentially static methods.
Change-Id: I54af7e8b48335b4b81594d4deeb0f75e21dbc932
Signed-off-by: Robert Varga <rovarga@cisco.com>
&& containsExi10Capability(sessionPreferences.getHelloMessage().getDocument());
}
- private boolean containsExi10Capability(final Document doc) {
+ private static boolean containsExi10Capability(final Document doc) {
final NodeList nList = doc.getElementsByTagName(XmlNetconfConstants.CAPABILITY);
for (int i = 0; i < nList.getLength(); i++) {
if (nList.item(i).getTextContent().contains(EXI_1_0_CAPABILITY_MARKER)) {
return false;
}
- private long extractSessionId(final Document doc) {
+ private static long extractSessionId(final Document doc) {
String textContent = getSessionIdWithXPath(doc, sessionIdXPath);
if (Strings.isNullOrEmpty(textContent)) {
textContent = getSessionIdWithXPath(doc, sessionIdXPathNoNamespace);
return Long.valueOf(textContent);
}
- private String getSessionIdWithXPath(final Document doc, final XPathExpression sessionIdXPath) {
+ private static String getSessionIdWithXPath(final Document doc, final XPathExpression sessionIdXPath) {
final Node sessionIdNode = (Node) XmlUtil.evaluateXPath(sessionIdXPath, doc, XPathConstants.NODE);
return sessionIdNode != null ? sessionIdNode.getTextContent() : null;
}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-
import com.google.common.base.Optional;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
channel = mockChannel();
}
- private ChannelHandler mockChannelHandler() {
+ private static ChannelHandler mockChannelHandler() {
ChannelHandler handler = mock(ChannelHandler.class);
return handler;
}
return channel;
}
- private ChannelFuture mockChannelFuture() {
+ private static ChannelFuture mockChannelFuture() {
ChannelFuture future = mock(ChannelFuture.class);
doReturn(future).when(future).addListener(any(GenericFutureListener.class));
return future;
}
- private ChannelPipeline mockChannelPipeline() {
+ private static ChannelPipeline mockChannelPipeline() {
ChannelPipeline pipeline = mock(ChannelPipeline.class);
ChannelHandler handler = mock(ChannelHandler.class);
doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
return builder.build();
}
- private Class<? extends Transport> getTransportForString(final String transport) {
+ private static Class<? extends Transport> getTransportForString(final String transport) {
switch(transport) {
case "ssh" :
return NetconfSsh.class;
}
}
- private String formatDateTime(final Date loginTime) {
+ private static String formatDateTime(final Date loginTime) {
+ // FIXME: thread-local cache?
SimpleDateFormat dateFormat = new SimpleDateFormat(ISO_DATE_FORMAT);
return dateFormat.format(loginTime);
}
private final NetconfOperationRouter operationRouter;
private final AutoCloseable onSessionDownCloseable;
- public NetconfServerSessionListener(final NetconfOperationRouter operationRouter, NetconfMonitoringService monitoringService,
+ public NetconfServerSessionListener(final NetconfOperationRouter operationRouter, final NetconfMonitoringService monitoringService,
final AutoCloseable onSessionDownCloseable) {
this.operationRouter = operationRouter;
this.monitoringService = monitoringService;
}
}
- private void checkMessageId(final Node rootNode) throws NetconfDocumentedException {
+ private static void checkMessageId(final Node rootNode) throws NetconfDocumentedException {
NamedNodeMap attributes = rootNode.getAttributes();
this.baseCapabilities = validateBaseCapabilities(baseCapabilities);
}
- private ImmutableSet<String> validateBaseCapabilities(final Set<String> baseCapabilities) {
+ private static ImmutableSet<String> validateBaseCapabilities(final Set<String> baseCapabilities) {
// Check base capabilities to be supported by the server
final Sets.SetView<String> unknownBaseCaps = Sets.difference(baseCapabilities, DEFAULT_BASE_CAPABILITIES);
Preconditions.checkArgument(unknownBaseCaps.isEmpty(),
private final NetconfMonitoringService cap;
private final NetconfOperationRouter operationRouter;
- public DefaultCommit(CommitNotifier notifier, NetconfMonitoringService cap,
- String netconfSessionIdForReporting, NetconfOperationRouter netconfOperationRouter) {
+ public DefaultCommit(final CommitNotifier notifier, final NetconfMonitoringService cap,
+ final String netconfSessionIdForReporting, final NetconfOperationRouter netconfOperationRouter) {
super(netconfSessionIdForReporting);
this.notificationProducer = notifier;
this.cap = cap;
}
@Override
- public Document handle(Document requestMessage, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
+ public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
Preconditions.checkArgument(!subsequentOperation.isExecutionTermination(),
"Subsequent netconf operation expected by %s", this);
}
@Override
- protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
+ protected Element handle(final Document document, final XmlElement message, final NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
throw new UnsupportedOperationException("Never gets called");
}
return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1);
}
- private void removePersisterAttributes(Document message) {
+ private static void removePersisterAttributes(final Document message) {
message.getDocumentElement().removeAttribute(NOTIFY_ATTR);
}
- private boolean isCommitWithoutNotification(Document message) {
+ private static boolean isCommitWithoutNotification(final Document message) {
XmlElement xmlElement = null;
try {
xmlElement = XmlElement.fromDomElementWithExpected(message.getDocumentElement(),
}
}
- private Element getConfigSnapshot(NetconfOperationRouter opRouter) throws NetconfDocumentedException {
+ private Element getConfigSnapshot(final NetconfOperationRouter opRouter) throws NetconfDocumentedException {
final Document responseDocument = opRouter.onNetconfMessage(
getConfigMessage, null);
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.util.concurrent.GenericFutureListener;
doReturn(mock(ChannelFuture.class)).when(channel).close();
final ChannelFuture sendFuture = mock(ChannelFuture.class);
- doAnswer(new Answer() {
+ doAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
((GenericFutureListener) invocation.getArguments()[0]).operationComplete(sendFuture);
this.state = newState;
}
- private boolean containsBase11Capability(final Document doc) {
+ private static boolean containsBase11Capability(final Document doc) {
final NodeList nList = doc.getElementsByTagName(XmlNetconfConstants.CAPABILITY);
for (int i = 0; i < nList.getLength(); i++) {
if (nList.item(i).getTextContent().contains(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1)) {
private long chunkSize;
private CompositeByteBuf chunk;
- private void checkNewLine(byte b,String errorMessage){
+ private static void checkNewLine(final byte b,final String errorMessage) {
if (b != '\n') {
LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM, b, (byte)'\n');
throw new IllegalStateException(errorMessage);
}
}
- private void checkHash(byte b,String errorMessage){
+ private static void checkHash(final byte b,final String errorMessage) {
if (b != '#') {
LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM, b, (byte)'#');
throw new IllegalStateException(errorMessage);
}
}
- private void checkChunkSize(){
+ private void checkChunkSize() {
if (chunkSize > maxChunkSize) {
LOG.debug("Parsed chunk size {}, maximum allowed is {}", chunkSize, maxChunkSize);
throw new IllegalStateException("Maximum chunk size exceeded");
}
-
}
+
@Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws IllegalStateException {
+ protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IllegalStateException {
while (in.isReadable()) {
switch (state) {
case HEADER_ONE:
in.discardReadBytes();
}
- private void extractNewChunkOrMessageEnd(byte b) {
+ private void extractNewChunkOrMessageEnd(final byte b) {
if (isHeaderLengthFirst(b)) {
// Extract header length#1 from new chunk
chunkSize = processHeaderLengthFirst(b);
chunk = Unpooled.compositeBuffer();
}
- private void aggregateChunks(ByteBuf newChunk) {
+ private void aggregateChunks(final ByteBuf newChunk) {
chunk.addComponent(chunk.numComponents(), newChunk);
// Update writer index, addComponent does not update it
chunk.writerIndex(chunk.writerIndex() + newChunk.readableBytes());
}
- private static int processHeaderLengthFirst(byte b) {
+ private static int processHeaderLengthFirst(final byte b) {
if (!isHeaderLengthFirst(b)) {
LOG.debug(GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM, b, (byte)'1', (byte)'9');
throw new IllegalStateException("Invalid chunk size encountered (byte 0)");
return b - '0';
}
- private static boolean isHeaderLengthFirst(byte b) {
+ private static boolean isHeaderLengthFirst(final byte b) {
return b >= '1' && b <= '9';
}
}
}
}
- private NetconfMessage getNetconfMessage(final String additionalHeader, final Document doc) throws NetconfDocumentedException {
+ private static NetconfMessage getNetconfMessage(final String additionalHeader, final Document doc) throws NetconfDocumentedException {
NetconfMessage msg = new NetconfMessage(doc);
if(NetconfHelloMessage.isHelloMessage(msg)) {
if (additionalHeader != null) {
return msg;
}
- private int getAdditionalHeaderEndIndex(final byte[] bytes) {
+ private static int getAdditionalHeaderEndIndex(final byte[] bytes) {
for (byte[] possibleEnd : POSSIBLE_ENDS) {
int idx = findByteSequence(bytes, possibleEnd);
return -1;
}
-
- private void logMessage(final byte[] bytes) {
- String s = Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
- LOG.debug("Parsing message \n{}", s);
+ private static void logMessage(final byte[] bytes) {
+ if (LOG.isDebugEnabled()) {
+ String s = Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
+ LOG.debug("Parsing message \n{}", s);
+ }
}
- private boolean startsWithAdditionalHeader(final byte[] bytes) {
+ private static boolean startsWithAdditionalHeader(final byte[] bytes) {
for (byte[] possibleStart : POSSIBLE_STARTS) {
int i = 0;
for (byte b : possibleStart) {
return false;
}
- private String additionalHeaderToString(final byte[] bytes) {
+ private static String additionalHeaderToString(final byte[] bytes) {
return Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
}
asyncIn = null;
}
- private Buffer toBuffer(final ByteBuf msg) {
+ private static Buffer toBuffer(final ByteBuf msg) {
// TODO Buffer vs ByteBuf translate, Can we handle that better ?
msg.resetReaderIndex();
final byte[] temp = new byte[msg.readableBytes()];
assertTrue(s.endsWith("\n#20\naaaaaaaaaaaaaaaaaaaa\n##\n"));
}
- private byte[] getByteArray(final int size) {
+ private static byte[] getByteArray(final int size) {
final byte[] bytes = new byte[size];
for (int i = 0; i < size; i++) {
bytes[i] = 'a';
this.msgAsExi = msgToExi(msgAsString, codec);
}
- private byte[] msgToExi(final String msgAsString, final NetconfEXICodec codec) throws EXIOptionsException, TransmogrifierException, IOException {
+ private static byte[] msgToExi(final String msgAsString, final NetconfEXICodec codec) throws EXIOptionsException, TransmogrifierException, IOException {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final Transmogrifier transmogrifier = codec.getTransmogrifier();
transmogrifier.setOutputStream(byteArrayOutputStream);
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
-
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
}
@SuppressWarnings("unchecked")
- private <T extends SshFuture<T>> ListenableFuture<SshFutureListener<T>> stubAddListener(final T future) {
+ private static <T extends SshFuture<T>> ListenableFuture<SshFutureListener<T>> stubAddListener(final T future) {
final SettableFuture<SshFutureListener<T>> listenerSettableFuture = SettableFuture.create();
doAnswer(new Answer<Object>() {
verify(ctx).fireChannelInactive();
}
- private OpenFuture getSuccessOpenFuture() {
+ private static OpenFuture getSuccessOpenFuture() {
final OpenFuture failedOpenFuture = mock(OpenFuture.class);
doReturn(true).when(failedOpenFuture).isOpened();
return failedOpenFuture;
}
- private AuthFuture getSuccessAuthFuture() {
+ private static AuthFuture getSuccessAuthFuture() {
final AuthFuture authFuture = mock(AuthFuture.class);
doReturn(true).when(authFuture).isSuccess();
return authFuture;
}
- private ConnectFuture getSuccessConnectFuture(final ClientSession sshSession) {
+ private static ConnectFuture getSuccessConnectFuture(final ClientSession sshSession) {
final ConnectFuture connectFuture = mock(ConnectFuture.class);
doReturn(true).when(connectFuture).isConnected();
return connectFuture;
}
- private ClientSession getMockedSshSession(final ChannelSubsystem subsystemChannel) throws IOException {
+ private static ClientSession getMockedSshSession(final ChannelSubsystem subsystemChannel) throws IOException {
final ClientSession sshSession = mock(ClientSession.class);
doReturn("sshSession").when(sshSession).toString();
return subsystemChannel;
}
- private IoOutputStream getMockedIoOutputStream() {
+ private static IoOutputStream getMockedIoOutputStream() {
final IoOutputStream mock = mock(IoOutputStream.class);
final IoWriteFuture ioWriteFuture = mock(IoWriteFuture.class);
doReturn(ioWriteFuture).when(ioWriteFuture).addListener(Matchers.<SshFutureListener<IoWriteFuture>>any());
return mock;
}
- private IoInputStream getMockedIoInputStream() {
+ private static IoInputStream getMockedIoInputStream() {
final IoInputStream mock = mock(IoInputStream.class);
final IoReadFuture ioReadFuture = mock(IoReadFuture.class);
doReturn(null).when(ioReadFuture).getException();
verify(promise).setFailure(any(Throwable.class));
}
- private AuthFuture getFailedAuthFuture() {
+ private static AuthFuture getFailedAuthFuture() {
final AuthFuture authFuture = mock(AuthFuture.class);
doReturn(false).when(authFuture).isSuccess();
doReturn(new IllegalStateException()).when(authFuture).getException();
return authFuture;
}
- private OpenFuture getFailedOpenFuture() {
+ private static OpenFuture getFailedOpenFuture() {
final OpenFuture authFuture = mock(OpenFuture.class);
doReturn(false).when(authFuture).isOpened();
doReturn(new IllegalStateException()).when(authFuture).getException();
verify(promise).setFailure(any(Throwable.class));
}
- private ConnectFuture getFailedConnectFuture() {
+ private static ConnectFuture getFailedConnectFuture() {
final ConnectFuture connectFuture = mock(ConnectFuture.class);
doReturn(false).when(connectFuture).isConnected();
doReturn(new IllegalStateException()).when(connectFuture).getException();
return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
}
- private StreamNameType parseStreamIfPresent(final XmlElement operationElement) throws NetconfDocumentedException {
+ private static StreamNameType parseStreamIfPresent(final XmlElement operationElement) throws NetconfDocumentedException {
final Optional<XmlElement> stream = operationElement.getOnlyChildElementWithSameNamespaceOptionally("stream");
return stream.isPresent() ? new StreamNameType(stream.get().getTextContent()) : NetconfNotificationManager.BASE_STREAM_NAME;
}
"</rpc-reply>\n");
}
- private Document getBlankResponse() throws IOException, SAXException {
+ private static Document getBlankResponse() throws IOException, SAXException {
return XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" +
"xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>netty-config-api</artifactId>
- <version>0.3.0-SNAPSHOT</version>
</dependency>
<dependency>
return new SshProxyServerConfiguration(bindingAddress, localAddress, authenticator, keyPairProvider, idleTimeout);
}
- public SshProxyServerConfigurationBuilder create () {
+ public static SshProxyServerConfigurationBuilder create() {
return new SshProxyServerConfigurationBuilder();
}
}
\ No newline at end of file
return authService;
}
- private Integer getPreference(final ServiceReference<AuthProvider> reference) {
+ private static Integer getPreference(final ServiceReference<AuthProvider> reference) {
final Object preferenceProperty = reference.getProperty(AuthConstants.SERVICE_PREFERENCE_KEY);
return preferenceProperty == null ? Integer.MIN_VALUE : Integer.valueOf(preferenceProperty.toString());
}