Skip to content

Commit

Permalink
Renamed CachedResource component to Res.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Jul 30, 2015
1 parent cfa5a20 commit 676bc63
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 34 deletions.
Expand Up @@ -28,7 +28,7 @@

import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.mime.MediaType;
import org.rapidoid.plugins.templates.ITemplate;

Expand Down Expand Up @@ -217,7 +217,7 @@ public interface HttpExchange {

HttpExchange sendFile(File file);

HttpExchange sendFile(CachedResource resource);
HttpExchange sendFile(Res resource);

HttpExchange sendFile(MediaType mediaType, byte[] bytes);

Expand Down
10 changes: 5 additions & 5 deletions rapidoid-http/src/main/java/org/rapidoid/http/HTMLSnippets.java
Expand Up @@ -25,21 +25,21 @@

import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.util.U;
import org.rapidoid.util.UTILS;

@Authors("Nikolche Mihajlovski")
@Since("2.0.0")
public class HTMLSnippets {

private static CachedResource PAGE_HTML;
private static Res PAGE_HTML;

private static CachedResource FULL_PAGE_HTML;
private static Res FULL_PAGE_HTML;

static {
PAGE_HTML = CachedResource.from("page.html");
FULL_PAGE_HTML = CachedResource.from("page-full.html");
PAGE_HTML = Res.from("page.html");
FULL_PAGE_HTML = Res.from("page-full.html");
}

public static HttpExchange writePage(HttpExchange x, String title, String content) {
Expand Down
Expand Up @@ -41,7 +41,7 @@
import org.rapidoid.data.Range;
import org.rapidoid.data.Ranges;
import org.rapidoid.http.session.SessionStore;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.json.JSON;
import org.rapidoid.log.Log;
import org.rapidoid.mime.MediaType;
Expand Down Expand Up @@ -743,7 +743,7 @@ public synchronized HttpExchange sendFile(File file) {
}

@Override
public synchronized HttpExchange sendFile(CachedResource resource) {
public synchronized HttpExchange sendFile(Res resource) {
U.must(resource.exists());
setContentType(MediaType.getByFileName(resource.getName()));
write(resource.getBytes());
Expand Down Expand Up @@ -941,7 +941,7 @@ public synchronized boolean serveStaticFile() {

@Override
public synchronized boolean serveStaticFile(String filename) {
CachedResource resource = CachedResource.from(filename);
Res resource = Res.from(filename);

if (resource.exists()) {
sendFile(resource);
Expand Down
Expand Up @@ -32,9 +32,9 @@

@Authors("Nikolche Mihajlovski")
@Since("4.1.0")
public class CachedResource {
public class Res {

private static final ConcurrentMap<String, CachedResource> FILES = U.concurrentMap();
private static final ConcurrentMap<String, Res> FILES = U.concurrentMap();

private final String name;

Expand All @@ -46,15 +46,15 @@ public class CachedResource {

private volatile String content;

public CachedResource(String name) {
public Res(String name) {
this.name = name;
}

public static CachedResource from(String filename) {
CachedResource cachedFile = FILES.get(filename);
public static Res from(String filename) {
Res cachedFile = FILES.get(filename);

if (cachedFile == null) {
cachedFile = new CachedResource(filename);
cachedFile = new Res(filename);

if (FILES.size() < 1000) {
FILES.putIfAbsent(filename, cachedFile);
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class CachedResourceTest extends TestCommons {

@Test
public void testWithExistingFiles() {
CachedResource file = CachedResource.from("abc.txt");
Res file = Res.from("abc.txt");
isTrue(file.exists());
eq(file.getBytes(), "ABC!".getBytes());
}
Expand All @@ -41,19 +41,19 @@ public void testWithExistingFiles() {
public void shouldBeFast() {
for (int i = 0; i < 900; i++) {
// fill-in the cache (with non-existing resources)
CachedResource.from("abc.txt" + i);
Res.from("abc.txt" + i);
}

// should be fast
for (int i = 0; i < 1000000; i++) {
CachedResource file = CachedResource.from("abc.txt");
Res file = Res.from("abc.txt");
notNull(file.getBytes());
}
}

@Test
public void testWithNonexistingFiles() {
CachedResource file = CachedResource.from("asfgsafd");
Res file = Res.from("asfgsafd");
isFalse(file.exists());
}

Expand Down
Expand Up @@ -37,7 +37,7 @@
import org.rapidoid.ctx.UserInfo;
import org.rapidoid.http.Handler;
import org.rapidoid.http.HttpExchange;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.json.JSON;
import org.rapidoid.log.Log;
import org.rapidoid.util.U;
Expand Down Expand Up @@ -114,7 +114,7 @@ public Object handle(HttpExchange x) throws Exception {
Ctxs.ctx().setUser(user);
user.saveTo(x.cookiepack());

x.write(CachedResource.from("close.html").getBytes());
x.write(Res.from("close.html").getBytes());
return x;
} else {
String error = x.param("error");
Expand Down
4 changes: 2 additions & 2 deletions rapidoid-pages/src/main/java/org/rapidoid/pages/Pages.java
Expand Up @@ -36,7 +36,7 @@
import org.rapidoid.http.HttpExchangeInternals;
import org.rapidoid.http.HttpNotFoundException;
import org.rapidoid.http.HttpSuccessException;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.json.JSON;
import org.rapidoid.lambda.Lambdas;
import org.rapidoid.lambda.Mapper;
Expand Down Expand Up @@ -385,7 +385,7 @@ public static boolean serveFromFile(HttpExchange x, Object app) {
}

public static boolean serveFromFile(HttpExchange x, String filename, Object app) {
CachedResource resource = CachedResource.from(filename);
Res resource = Res.from(filename);

if (resource.exists()) {
x.html();
Expand Down
Expand Up @@ -24,7 +24,7 @@

import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.io.IO;
import org.rapidoid.log.Log;

Expand Down Expand Up @@ -74,7 +74,7 @@ public void invalidateCache() {

@Override
public Reader getReader(String resourceName) {
CachedResource res = CachedResource.from(resourceName);
Res res = Res.from(resourceName);
return res.getReader();
}

Expand Down
8 changes: 4 additions & 4 deletions rapidoid-watch/src/main/java/org/rapidoid/io/watch/Dir.java
Expand Up @@ -17,7 +17,7 @@

import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.lambda.Mapper;
import org.rapidoid.log.Log;
import org.rapidoid.util.U;
Expand Down Expand Up @@ -59,7 +59,7 @@ public Dir map(String path) throws Exception {

private final File dir;

private final Set<CachedResource> files = U.set();
private final Set<Res> files = U.set();

private final Set<String> folders = U.set();

Expand Down Expand Up @@ -109,7 +109,7 @@ public synchronized void refresh() {

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
files.add(CachedResource.from(file.toAbsolutePath().toString()));
files.add(Res.from(file.toAbsolutePath().toString()));
return super.visitFile(file, attrs);
}

Expand All @@ -128,7 +128,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
dirty = false;
}

public synchronized Set<CachedResource> files() {
public synchronized Set<Res> files() {
return files;
}

Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.junit.Test;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.io.CachedResource;
import org.rapidoid.io.Res;
import org.rapidoid.io.IO;
import org.rapidoid.log.Log;
import org.rapidoid.test.TestCommons;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void testDirRefresh() throws IOException {

giveItTimeToRefresh();

CachedResource resA = CachedResource.from(fileA);
Res resA = Res.from(fileA);
eq(dir.files(), U.set(resA));
eq(dir.folders(), U.set());

Expand All @@ -83,7 +83,7 @@ public void testDirRefresh() throws IOException {

giveItTimeToRefresh();

CachedResource resB = CachedResource.from(fileB);
Res resB = Res.from(fileB);
eq(dir.files(), U.set(resA, resB));
eq(dir.folders(), U.set());

Expand Down Expand Up @@ -122,7 +122,7 @@ public void testDirRefresh() throws IOException {

giveItTimeToRefresh();

CachedResource resX = CachedResource.from(fileX);
Res resX = Res.from(fileX);
eq(dir.files(), U.set(resB, resX));
eq(dir.folders(), U.set(dirC));

Expand Down

0 comments on commit 676bc63

Please sign in to comment.