Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize line endings: text files are stored with LF in the repository.
* text=auto
12 changes: 0 additions & 12 deletions .prettierrc.yaml

This file was deleted.

401 changes: 401 additions & 0 deletions metricshub-eclipse-formatter.xml

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,30 @@
<!-- Actual build plugins -->
<plugins>

<!-- Prettier -->
<!-- formatter -->
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>0.22</version>
<configuration>
<prettierJavaVersion>2.5.0</prettierJavaVersion>
<ignoreConfigFile>false</ignoreConfigFile>
<ignoreEditorConfig>false</ignoreEditorConfig>
<inputGlobs>
<inputGlob>src/main/java/**/*.java</inputGlob>
<inputGlob>src/test/java/**/*.java</inputGlob>
</inputGlobs>
</configuration>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.29.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
<goal>validate</goal>
</goals>
</execution>
</executions>
<configuration>
<directories>
<directory>${project.build.sourceDirectory}</directory>
<directory>${project.build.testSourceDirectory}</directory>
</directories>
<includes>
<include>**/*.java</include>
</includes>
<configFile>metricshub-eclipse-formatter.xml</configFile>
<lineEnding>KEEP</lineEnding>
</configuration>
</plugin>

</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package org.metricshub.winrm;
/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* WinRM Java Client
* ჻჻჻჻჻჻
* Copyright 2023 - 2024 Metricshub
* ჻჻჻჻჻჻
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/
@FunctionalInterface
public interface ShareRemoteDirectoryConsumer<W extends WindowsRemoteExecutor, R, S, T> {
/**
* Share the remote directory on the host.
*
* @param windowsRemoteExecutor WindowsRemoteExecutor instance.
* @param remotePath The remote path.
* @param shareName The Share Name.
* @param timeout Timeout in milliseconds.
*/
public void apply(final W windowsRemoteExecutor, final R remotePath, final S shareName, final T timeout);
}
package org.metricshub.winrm;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* WinRM Java Client
* ჻჻჻჻჻჻
* Copyright 2023 - 2026 MetricsHub
* ჻჻჻჻჻჻
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

@FunctionalInterface
public interface ShareRemoteDirectoryConsumer<W extends WindowsRemoteExecutor, R, S, T> {
/**
* Share the remote directory on the host.
*
* @param windowsRemoteExecutor WindowsRemoteExecutor instance.
* @param remotePath The remote path.
* @param shareName The Share Name.
* @param timeout Timeout in milliseconds.
*/
public void apply(final W windowsRemoteExecutor, final R remotePath, final S shareName, final T timeout);

Check warning on line 33 in src/main/java/org/metricshub/winrm/ShareRemoteDirectoryConsumer.java

View workflow job for this annotation

GitHub Actions / PMD

Code Style UnnecessaryModifier

Unnecessary modifier 'public' on method 'apply': the method is declared in an interface type
}
182 changes: 90 additions & 92 deletions src/main/java/org/metricshub/winrm/TimeoutHelper.java
Original file line number Diff line number Diff line change
@@ -1,92 +1,90 @@
package org.metricshub.winrm;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* WinRM Java Client
* ჻჻჻჻჻჻
* Copyright 2023 - 2024 Metricshub
* ჻჻჻჻჻჻
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import java.util.concurrent.TimeoutException;

/**
* for stagged timeout handling.
*
*/
public class TimeoutHelper {

private TimeoutHelper() {}

/**
* Get the remaining time before timeout.
*
* @param timeout Timeout in milliseconds. (throws an IllegalArgumentException if negative or zero)
* @param start start time in milliseconds. (throws an IllegalArgumentException if negative or zero)
* @return The remaining time
* @throws TimeoutException if there's no time left
*/
public static long getRemainingTime(final long timeout, final long start, final String message)
throws TimeoutException {
long remaining = start + timeout - Utils.getCurrentTimeMillis();
if (remaining < 0) {
throw new TimeoutException(message);
}
return remaining;
}

/**
* Sub to make the thread sleep in a stepped delay.
* <p>Delay:
* <ul>
* <li>50 milliseconds for time from start &lt; 500 milliseconds</li>
* <li>100 milliseconds for time from start between 500 milliseconds and 1 second</li>
* <li>250 milliseconds for time from start between 1 second and 5 seconds</li>
* <li>500 milliseconds for time from start between 5 seconds and 10 seconds</li>
* <li>1 second for time from start between 10 seconds and 30 seconds</li>
* <li>3 seconds otherwise</li>
* </ul>
*
* @param timeout Timeout in milliseconds
* @param start start time in milliseconds
* @param message The timeout error message
*
* @throws TimeoutException when times out
*
*/
public static void stagedSleep(final long timeout, final long start, final String message) throws TimeoutException {
// Check we still have some time on our hands
getRemainingTime(timeout, start, message);

final long elapsedTime = Utils.getCurrentTimeMillis() - start;
try {
if (elapsedTime < 500) {
Utils.sleep(50);
} else if (elapsedTime < 1000) {
Utils.sleep(100);
} else if (elapsedTime < 5000) {
Utils.sleep(250);
} else if (elapsedTime < 10000) {
Utils.sleep(500);
} else if (elapsedTime < 30000) {
Utils.sleep(1000);
} else {
Utils.sleep(3000);
}
} catch (InterruptedException e) {
throw new TimeoutException(message);
}
}
}
package org.metricshub.winrm;

/*-
* ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
* WinRM Java Client
* ჻჻჻჻჻჻
* Copyright 2023 - 2026 MetricsHub
* ჻჻჻჻჻჻
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
*/

import java.util.concurrent.TimeoutException;

/**
* for stagged timeout handling.
*/
public class TimeoutHelper {

private TimeoutHelper() {}

/**
* Get the remaining time before timeout.
*
* @param timeout Timeout in milliseconds. (throws an IllegalArgumentException if negative or zero)
* @param start start time in milliseconds. (throws an IllegalArgumentException if negative or zero)
* @return The remaining time
* @throws TimeoutException if there's no time left
*/
public static long getRemainingTime(final long timeout, final long start, final String message)
throws TimeoutException {
long remaining = start + timeout - Utils.getCurrentTimeMillis();
if (remaining < 0) {
throw new TimeoutException(message);
}
return remaining;
}

/**
* Sub to make the thread sleep in a stepped delay.
* <p>
* Delay:
* <ul>
* <li>50 milliseconds for time from start &lt; 500 milliseconds</li>
* <li>100 milliseconds for time from start between 500 milliseconds and 1 second</li>
* <li>250 milliseconds for time from start between 1 second and 5 seconds</li>
* <li>500 milliseconds for time from start between 5 seconds and 10 seconds</li>
* <li>1 second for time from start between 10 seconds and 30 seconds</li>
* <li>3 seconds otherwise</li>
* </ul>
*
* @param timeout Timeout in milliseconds
* @param start start time in milliseconds
* @param message The timeout error message
* @throws TimeoutException when times out
*/
public static void stagedSleep(final long timeout, final long start, final String message) throws TimeoutException {
// Check we still have some time on our hands
getRemainingTime(timeout, start, message);

final long elapsedTime = Utils.getCurrentTimeMillis() - start;
try {
if (elapsedTime < 500) {
Utils.sleep(50);
} else if (elapsedTime < 1000) {
Utils.sleep(100);
} else if (elapsedTime < 5000) {
Utils.sleep(250);
} else if (elapsedTime < 10000) {
Utils.sleep(500);
} else if (elapsedTime < 30000) {
Utils.sleep(1000);
} else {
Utils.sleep(3000);
}
} catch (InterruptedException e) {
throw new TimeoutException(message);
}
}
}
Loading
Loading