Moved NamedThreadFactory and ByteArrayWrapper to util project. Changed try/catch with hashing files in Crypto.Util
This commit is contained in:
parent
7f345cb963
commit
93c7d78ab6
|
@ -32,11 +32,11 @@ import dorkbox.network.connection.registration.local.RegistrationLocalHandlerCli
|
|||
import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerClientTCP;
|
||||
import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerClientUDP;
|
||||
import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerClientUDT;
|
||||
import dorkbox.network.util.NamedThreadFactory;
|
||||
import dorkbox.network.util.SerializationManager;
|
||||
import dorkbox.network.util.exceptions.InitializationException;
|
||||
import dorkbox.network.util.exceptions.SecurityException;
|
||||
import dorkbox.network.util.udt.UdtEndpointProxy;
|
||||
import dorkbox.util.NamedThreadFactory;
|
||||
|
||||
/**
|
||||
* The client is both SYNC and ASYNC, meaning that once the client is connected to the server, you can access it however you want.
|
||||
|
|
|
@ -22,10 +22,10 @@ import dorkbox.network.connection.registration.local.RegistrationLocalHandlerSer
|
|||
import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerServerTCP;
|
||||
import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerServerUDP;
|
||||
import dorkbox.network.connection.registration.remote.RegistrationRemoteHandlerServerUDT;
|
||||
import dorkbox.network.util.NamedThreadFactory;
|
||||
import dorkbox.network.util.exceptions.InitializationException;
|
||||
import dorkbox.network.util.exceptions.SecurityException;
|
||||
import dorkbox.network.util.udt.UdtEndpointProxy;
|
||||
import dorkbox.util.NamedThreadFactory;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,9 +9,9 @@ import java.util.Map;
|
|||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
|
||||
import dorkbox.network.util.ByteArrayWrapper;
|
||||
import dorkbox.network.util.store.SettingsStore;
|
||||
import dorkbox.util.Storage;
|
||||
import dorkbox.util.bytes.ByteArrayWrapper;
|
||||
import dorkbox.util.properties.PropertiesProvider;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package dorkbox.network.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Necessary to provide equals and hashcode for byte arrays (if they are to be used as keys in a map/set/etc)
|
||||
*/
|
||||
public final class ByteArrayWrapper {
|
||||
private final byte[] data;
|
||||
|
||||
public ByteArrayWrapper(byte[] data) {
|
||||
if (data == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
int length = data.length;
|
||||
this.data = new byte[length];
|
||||
// copy so it's immutable as a key.
|
||||
System.arraycopy(data, 0, this.data, 0, length);
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ByteArrayWrapper)) {
|
||||
return false;
|
||||
}
|
||||
return Arrays.equals(this.data, ((ByteArrayWrapper) other).data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(this.data);
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package dorkbox.network.util;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* The default thread factory with names.
|
||||
*/
|
||||
public class NamedThreadFactory implements ThreadFactory {
|
||||
private static final AtomicInteger poolId = new AtomicInteger();
|
||||
// permit this to be changed!
|
||||
/**
|
||||
* Stack size must be specified in bytes. Default is 8k
|
||||
*/
|
||||
public static int stackSizeForNettyThreads = 8192;
|
||||
|
||||
private final AtomicInteger nextId = new AtomicInteger();
|
||||
|
||||
final ThreadGroup group;
|
||||
final String namePrefix;
|
||||
|
||||
public NamedThreadFactory(String poolNamePrefix, ThreadGroup group) {
|
||||
this.group = group;
|
||||
namePrefix = poolNamePrefix + '-' + poolId.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
// stack size is arbitrary based on JVM implementation. Default is 0
|
||||
// 8k is the size of the android stack. Depending on the version of android, this can either change, or will always be 8k
|
||||
// To be honest, 8k is pretty reasonable for an asynchronous/event based system (32bit) or 16k (64bit)
|
||||
// Setting the size MAY or MAY NOT have any effect!!!
|
||||
Thread t = new Thread(group, r, namePrefix + '-' + nextId.incrementAndGet(), stackSizeForNettyThreads);
|
||||
if (!t.isDaemon()) {
|
||||
t.setDaemon(true);
|
||||
}
|
||||
if (t.getPriority() != Thread.MAX_PRIORITY) {
|
||||
t.setPriority(Thread.MAX_PRIORITY);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package dorkbox.network.util.udt;
|
||||
|
||||
import dorkbox.network.util.NamedThreadFactory;
|
||||
|
||||
import dorkbox.util.NamedThreadFactory;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
|
|
Loading…
Reference in New Issue