use of java.util.LinkedHashSet in project grails-core by grails.
the class PathMatchingResourcePatternResolver method doFindPathMatchingJarResources.
/**
* Find all resources in jar files that match the given location pattern
* via the Ant-style PathMatcher.
* @param rootDirResource the root directory as Resource
* @param subPattern the sub pattern to match (below the root directory)
* @return the Set of matching Resource instances
* @throws IOException in case of I/O errors
* @see java.net.JarURLConnection
*/
protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, String subPattern) throws IOException {
URLConnection con = rootDirResource.getURL().openConnection();
JarFile jarFile;
String jarFileUrl;
String rootEntryPath;
boolean newJarFile = false;
if (con instanceof JarURLConnection) {
// Should usually be the case for traditional JAR files.
JarURLConnection jarCon = (JarURLConnection) con;
GrailsResourceUtils.useCachesIfNecessary(jarCon);
jarFile = jarCon.getJarFile();
jarFileUrl = jarCon.getJarFileURL().toExternalForm();
JarEntry jarEntry = jarCon.getJarEntry();
rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
} else {
// No JarURLConnection -> need to resort to URL file parsing.
// We'll assume URLs of the format "jar:path!/entry", with the protocol
// being arbitrary as long as following the entry format.
// We'll also handle paths with and without leading "file:" prefix.
String urlFile = rootDirResource.getURL().getFile();
int separatorIndex = urlFile.indexOf(GrailsResourceUtils.JAR_URL_SEPARATOR);
if (separatorIndex != -1) {
jarFileUrl = urlFile.substring(0, separatorIndex);
rootEntryPath = urlFile.substring(separatorIndex + GrailsResourceUtils.JAR_URL_SEPARATOR.length());
jarFile = getJarFile(jarFileUrl);
} else {
jarFile = new JarFile(urlFile);
jarFileUrl = urlFile;
rootEntryPath = "";
}
newJarFile = true;
}
try {
if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
// Root entry path must end with slash to allow for proper matching.
// The Sun JRE does not return a slash here, but BEA JRockit does.
rootEntryPath = rootEntryPath + "/";
}
Set<Resource> result = new LinkedHashSet<Resource>(8);
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) {
JarEntry entry = entries.nextElement();
String entryPath = entry.getName();
if (entryPath.startsWith(rootEntryPath)) {
String relativePath = entryPath.substring(rootEntryPath.length());
if (getPathMatcher().match(subPattern, relativePath)) {
result.add(rootDirResource.createRelative(relativePath));
}
}
}
return result;
} finally {
// not from JarURLConnection, which might cache the file reference.
if (newJarFile) {
jarFile.close();
}
}
}
use of java.util.LinkedHashSet in project groovy-core by groovy.
the class SourceExtensionHandler method getRegisteredExtensions.
public static Set<String> getRegisteredExtensions(ClassLoader loader) {
Set<String> extensions = new LinkedHashSet<String>();
extensions.add("groovy");
try {
Enumeration<URL> globalServices = loader.getResources("META-INF/services/org.codehaus.groovy.source.Extensions");
while (globalServices.hasMoreElements()) {
BufferedReader svcIn = null;
URL service = globalServices.nextElement();
try {
svcIn = new BufferedReader(new InputStreamReader(service.openStream()));
String extension = svcIn.readLine();
while (extension != null) {
extension = extension.trim();
if (!extension.startsWith("#") && extension.length() > 0) {
extensions.add(extension);
}
extension = svcIn.readLine();
}
} catch (IOException ex) {
throw new GroovyRuntimeException("IO Exception attempting to load registered source extension " + service.toExternalForm() + ". Exception: " + ex.toString());
} finally {
if (svcIn != null)
svcIn.close();
}
}
} catch (IOException ex) {
throw new GroovyRuntimeException("IO Exception getting registered source extensions. Exception: " + ex.toString());
}
return extensions;
}
use of java.util.LinkedHashSet in project groovy-core by groovy.
the class TraitComposer method createSuperForwarder.
/**
* Creates, if necessary, a super forwarder method, for stackable traits.
* @param forwarder a forwarder method
* @param genericsSpec
*/
private static void createSuperForwarder(ClassNode targetNode, MethodNode forwarder, final Map<String, ClassNode> genericsSpec) {
List<ClassNode> interfaces = new ArrayList<ClassNode>(Traits.collectAllInterfacesReverseOrder(targetNode, new LinkedHashSet<ClassNode>()));
String name = forwarder.getName();
Parameter[] forwarderParameters = forwarder.getParameters();
LinkedHashSet<ClassNode> traits = new LinkedHashSet<ClassNode>();
List<MethodNode> superForwarders = new LinkedList<MethodNode>();
for (ClassNode node : interfaces) {
if (Traits.isTrait(node)) {
MethodNode method = node.getDeclaredMethod(name, forwarderParameters);
if (method != null) {
// a similar method exists, we need a super bridge
// trait$super$foo(Class currentTrait, ...)
traits.add(node);
superForwarders.add(method);
}
}
}
for (MethodNode superForwarder : superForwarders) {
doCreateSuperForwarder(targetNode, superForwarder, traits.toArray(new ClassNode[traits.size()]), genericsSpec);
}
}
use of java.util.LinkedHashSet in project hazelcast by hazelcast.
the class ClusterServiceImpl method sendMembershipEvents.
private void sendMembershipEvents(Collection<MemberImpl> currentMembers, Collection<MemberImpl> newMembers) {
Set<Member> eventMembers = new LinkedHashSet<Member>(currentMembers);
if (!newMembers.isEmpty()) {
if (newMembers.size() == 1) {
MemberImpl newMember = newMembers.iterator().next();
// sync call
node.getPartitionService().memberAdded(newMember);
// async events
eventMembers.add(newMember);
sendMembershipEventNotifications(newMember, unmodifiableSet(eventMembers), true);
} else {
for (MemberImpl newMember : newMembers) {
// sync call
node.getPartitionService().memberAdded(newMember);
// async events
eventMembers.add(newMember);
sendMembershipEventNotifications(newMember, unmodifiableSet(new LinkedHashSet<Member>(eventMembers)), true);
}
}
}
}
use of java.util.LinkedHashSet in project hazelcast by hazelcast.
the class ClusterServiceImpl method shrinkMembersRemovedWhileClusterIsNotActiveState.
public void shrinkMembersRemovedWhileClusterIsNotActiveState(Collection<String> memberUuidsToRemove) {
lock.lock();
try {
Set<MemberImpl> membersRemovedInNotActiveState = new LinkedHashSet<MemberImpl>(membersRemovedInNotActiveStateRef.get().getMembers());
Iterator<MemberImpl> it = membersRemovedInNotActiveState.iterator();
while (it.hasNext()) {
MemberImpl member = it.next();
if (memberUuidsToRemove.contains(member.getUuid())) {
logger.fine("Removing " + member + " from members removed while in cluster not active state");
it.remove();
}
}
membersRemovedInNotActiveStateRef.set(MemberMap.createNew(membersRemovedInNotActiveState.toArray(new MemberImpl[0])));
} finally {
lock.unlock();
}
}
Aggregations