com.epam.deltix.thread.affinity.RegExAffinityLayout Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thread-affinity Show documentation
Show all versions of thread-affinity Show documentation
A wrapper over net.openhft:affinity providing handy classes to create threads pinned to the specified CPUs.
The newest version!
package com.epam.deltix.thread.affinity;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.BitSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ParametersAreNonnullByDefault
public class RegExAffinityLayout implements AffinityLayout {
protected final Pattern pattern;
protected final BitSet mask;
public RegExAffinityLayout(@Nonnull String regexp, @Nonnull BitSet mask) {
this.pattern = Pattern.compile(regexp);
this.mask = mask;
}
@Override
@Nonnull
public BitSet getMask(@Nonnull final Thread thread) {
final String name = thread.getName();
final Matcher matcher = pattern.matcher(name);
return matcher.matches() ? mask : new BitSet();
}
}