use of java.net.URL in project groovy by apache.
the class BaseTemplate method includeEscaped.
/**
* Includes contents of another file, not as a template but as escaped text.
*
* @param templatePath the path to the other file
* @throws IOException
*/
public void includeEscaped(String templatePath) throws IOException {
URL resource = engine.resolveTemplate(templatePath);
yield(ResourceGroovyMethods.getText(resource, engine.getCompilerConfiguration().getSourceEncoding()));
}
use of java.net.URL in project groovy by apache.
the class CompilerPerformanceTest method main.
public static void main(String[] args) throws Exception {
List<File> sources = new ArrayList<>();
List<URL> classpath = new ArrayList<>();
boolean isCp = false;
for (String arg : args) {
if ("-cp".equals(arg)) {
isCp = true;
} else if (isCp) {
classpath.add(new File(arg).toURI().toURL());
} else {
sources.add(new File(arg));
}
}
ScriptCompilationExecuter executer = new ScriptCompilationExecuter(sources.toArray(new File[sources.size()]), classpath);
System.out.println("Using Groovy " + GROOVY_VERSION);
DescriptiveStatistics stats = new DescriptiveStatistics();
for (int i = 0; i < WARMUP + REPEAT; i++) {
if (i < WARMUP) {
System.out.println("Warmup #" + (i + 1));
} else {
System.out.println("Round #" + (i - WARMUP));
}
long dur = executer.execute();
System.gc();
System.out.printf("Compile time = %dms%n", dur);
if (i >= WARMUP) {
stats.addValue((double) dur);
}
}
System.out.println("Compilation took " + stats.getMean() + "ms ± " + stats.getStandardDeviation() + "ms");
FileWriter wrt = new FileWriter(new File("target/compilation-stats.csv"), true);
wrt.append(String.format("%s;%s;%s\n", GROOVY_VERSION, stats.getMean(), stats.getStandardDeviation()));
wrt.close();
}
use of java.net.URL in project hadoop by apache.
the class DelegationTokenAuthenticatedURL method augmentURL.
private URL augmentURL(URL url, Map<String, String> params) throws IOException {
if (params != null && params.size() > 0) {
String urlStr = url.toExternalForm();
StringBuilder sb = new StringBuilder(urlStr);
String separator = (urlStr.contains("?")) ? "&" : "?";
for (Map.Entry<String, String> param : params.entrySet()) {
sb.append(separator).append(param.getKey()).append("=").append(param.getValue());
separator = "&";
}
url = new URL(sb.toString());
}
return url;
}
use of java.net.URL in project flink by apache.
the class JobClient method retrieveClassLoader.
/**
* Reconstructs the class loader by first requesting information about it at the JobManager
* and then downloading missing jar files.
* @param jobID id of job
* @param jobManager gateway to the JobManager
* @param config the flink configuration
* @return A classloader that should behave like the original classloader
* @throws JobRetrievalException if anything goes wrong
*/
public static ClassLoader retrieveClassLoader(JobID jobID, ActorGateway jobManager, Configuration config) throws JobRetrievalException {
final Object jmAnswer;
try {
jmAnswer = Await.result(jobManager.ask(new JobManagerMessages.RequestClassloadingProps(jobID), AkkaUtils.getDefaultTimeoutAsFiniteDuration()), AkkaUtils.getDefaultTimeoutAsFiniteDuration());
} catch (Exception e) {
throw new JobRetrievalException(jobID, "Couldn't retrieve class loading properties from JobManager.", e);
}
if (jmAnswer instanceof JobManagerMessages.ClassloadingProps) {
JobManagerMessages.ClassloadingProps props = ((JobManagerMessages.ClassloadingProps) jmAnswer);
Option<String> jmHost = jobManager.actor().path().address().host();
String jmHostname = jmHost.isDefined() ? jmHost.get() : "localhost";
InetSocketAddress serverAddress = new InetSocketAddress(jmHostname, props.blobManagerPort());
final BlobCache blobClient;
try {
blobClient = new BlobCache(serverAddress, config);
} catch (IOException e) {
throw new JobRetrievalException(jobID, "Failed to setup blob cache", e);
}
final Collection<BlobKey> requiredJarFiles = props.requiredJarFiles();
final Collection<URL> requiredClasspaths = props.requiredClasspaths();
final URL[] allURLs = new URL[requiredJarFiles.size() + requiredClasspaths.size()];
int pos = 0;
for (BlobKey blobKey : props.requiredJarFiles()) {
try {
allURLs[pos++] = blobClient.getURL(blobKey);
} catch (Exception e) {
blobClient.shutdown();
throw new JobRetrievalException(jobID, "Failed to download BlobKey " + blobKey, e);
}
}
for (URL url : requiredClasspaths) {
allURLs[pos++] = url;
}
return new FlinkUserCodeClassLoader(allURLs, JobClient.class.getClassLoader());
} else if (jmAnswer instanceof JobManagerMessages.JobNotFound) {
throw new JobRetrievalException(jobID, "Couldn't retrieve class loader. Job " + jobID + " not found");
} else {
throw new JobRetrievalException(jobID, "Unknown response from JobManager: " + jmAnswer);
}
}
use of java.net.URL in project flink by apache.
the class BlobLibraryCacheManager method registerTask.
@Override
public void registerTask(JobID jobId, ExecutionAttemptID task, Collection<BlobKey> requiredJarFiles, Collection<URL> requiredClasspaths) throws IOException {
checkNotNull(jobId, "The JobId must not be null.");
checkNotNull(task, "The task execution id must not be null.");
if (requiredJarFiles == null) {
requiredJarFiles = Collections.emptySet();
}
if (requiredClasspaths == null) {
requiredClasspaths = Collections.emptySet();
}
synchronized (lockObject) {
LibraryCacheEntry entry = cacheEntries.get(jobId);
if (entry == null) {
// create a new entry in the library cache
BlobKey[] keys = requiredJarFiles.toArray(new BlobKey[requiredJarFiles.size()]);
URL[] urls = new URL[keys.length + requiredClasspaths.size()];
int count = 0;
try {
for (; count < keys.length; count++) {
BlobKey blobKey = keys[count];
urls[count] = registerReferenceToBlobKeyAndGetURL(blobKey);
}
} catch (Throwable t) {
// undo the reference count increases
try {
for (int i = 0; i < count; i++) {
unregisterReferenceToBlobKey(keys[i]);
}
} catch (Throwable tt) {
LOG.error("Error while updating library reference counters.", tt);
}
// rethrow or wrap
ExceptionUtils.tryRethrowIOException(t);
throw new IOException("Library cache could not register the user code libraries.", t);
}
// add classpaths
for (URL url : requiredClasspaths) {
urls[count] = url;
count++;
}
cacheEntries.put(jobId, new LibraryCacheEntry(requiredJarFiles, urls, task));
} else {
entry.register(task, requiredJarFiles);
}
}
}
Aggregations