![JAR search and dependency download from the Maven repository](/logo.png)
org.nustaq.fastcast.util.FCUtils Maven / Gradle / Ivy
/*
* Copyright 2014 Ruediger Moeller.
*
* 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.
*/
package org.nustaq.fastcast.util;
import org.nustaq.fastcast.impl.Packet;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.*;
/**
*/
public class FCUtils {
public static String createNodeId( String addendum ) {
final String name = addendum + "-" + toUnsignedString((int) (Math.random()*0xfffff), 5);
if ( name.length() > Packet.MAX_NODE_NAME_LEN)
throw new RuntimeException("node name '"+name+"' too long. Max length is "+Packet.MAX_NODE_NAME_LEN);
return name;
}
private static String toUnsignedString(int i, int shift) {
char[] buf = new char[32];
int charPos = 32;
int radix = 1 << shift;
int mask = radix - 1;
do {
buf[--charPos] = digits[i & mask];
i >>>= shift;
} while (i != 0);
return new String(buf, charPos, (32 - charPos));
}
final static char[] digits = {
'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z'
};
public static boolean isWindows() {
return System.getProperty("os.name","").indexOf("indows") > 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy