Permalink
Browse files

docs

  • Loading branch information...
pron committed Jul 23, 2014
1 parent 1acdc06 commit 81a175e83f7030cecdd46f04e6121571aee6f893
@@ -0,0 +1,98 @@
# Title: Include Snippet Tag for Jekyll
# Author: Eitan Yarden https://github.com/eitan101
# Description: Import your code snippets into any blog post.
# Configuration: You can set default import path in _config.yml (defaults to code_dir: downloads/code)
#
# Syntax {% include_snippet snippet_name path/to/file %}
#
# Example 1:
# ~~~ java
# {% include_code hello world javascripts/test.java %}
# ~~~
#
# This will import test.js starting from the line which contains "snippet hello world" till
# the line which contains "end of snippet". You can use the "snippet_exclude_begin" and "snippet_exclude_end // ..." for
# block exclusion. For code higlight wrap the tag with the appropritate md tag.
#
#
require 'pathname'
module Jekyll
class IncludeCodeTag < Liquid::Tag
# include HighlightCode
# include TemplateWrapper
def initialize(tag_name, markup, tokens)
@title = nil
if markup.strip =~ /(.*)?(\s+|^)(\/*\S+)/i
@title = $1 || nil
@file = $3
else
fail "no title in '#{markup.strip}'"
end
super
end
def render(context)
code_dir = (context.registers[:site].config['code_dir'].sub(/^\//,'') || 'downloads/code')
code_path = (Pathname.new(context.registers[:site].source) + code_dir).expand_path
file = code_path + @file
if File.symlink?(code_path)
return "Code directory '#{code_path}' cannot be a symlink"
end
unless file.file?
fail "File #{file} could not be found"
end
Dir.chdir(code_path) do
code = file.read
source = ""
inblock = false
exclude = false
spaces = -1;
snippet_found = false
code.lines.each_with_index do |line,index|
if line =~ /end of snippet/
inblock = false
end
if (line =~ /snippet_exclude_begin/)
exclude = true
end
if inblock && !exclude
if spaces==-1
spaces = line.index(/[^ ]/)
end
if spaces>-1 && spaces <= line.index(/[^ ]/)
line = line[spaces..line.length]
end
source += "#{line}"
end
if (line =~ /snippet_exclude_end/)
# add what comes after "snippet_exclude_end" as a block replacement
# for example "// ..."
# update: disabled. causes problems in cases like <!--snippet_exclude_end-->
# index = line.index(/snippet_exclude_end/)
# if (index) + 20 +1 < line.length
# source += line[index+20..line.length]
# end
exclude = false
end
if line =~ /snippet #{@title}/
inblock = true
snippet_found = true
end
end
if not snippet_found
fail "snippet #{@title} not found in #{file}"
end
ouput = source
end
end
end
end
Liquid::Template.register_tag('include_snippet', Jekyll::IncludeCodeTag)
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -729,7 +729,8 @@ protected Message handleLifecycleMessage(LifecycleMessage m) {
/**
* Tests whether this actor has been upgraded via hot code-swapping.
* If a new version of this actor is found, this method never returns.
* If a new version of this actor is found, this method never returns
* (a special {@code Error} is thrown which causes the actor to restart).
*
* @throws SuspendExecution
*/
@@ -1005,6 +1006,11 @@ boolean isMigrating() {
return migrating;
}
/**
* Suspends and migrates the actor in such a way that when it is later hired, the actor is restarted
* (i.e., its `doRun` method will be called again and run from the top), but the current value of the actor's fields will be preserved.
* This method never returns.
*/
public void migrateAndRestart() throws SuspendExecution {
record(1, "Actor", "migrateAndRestart", "Actor %s is migrating.", this);
verifyOnActorStrand();
@@ -1022,9 +1028,10 @@ public void migrateAndRestart() throws SuspendExecution {
}
/**
* Must be called on a fiber.
*
* @throws SuspendExecution
* Suspends and migrate the actor.
* This method suspends the fiber the actor is running in (and is therefore available only for actors running in fibers),
* so that when the actor is hired, it will continue execution from the point this method was called.
* This method must be called on a fiber.
*/
public void migrate() throws SuspendExecution {
record(1, "Actor", "migrate", "Actor %s is migrating.", this);
@@ -1061,7 +1068,7 @@ private void preMigrate() {
private void postMigrate() {
assert ref.getImpl() instanceof RemoteActor;
// copy messages already in the mailbox
// TODO: this might change the message order, as new messages are coming in
final Mailbox mbox = mailbox();
@@ -1074,10 +1081,24 @@ private void postMigrate() {
}
}
/**
* Hires and resumes/restarts a migrated actor.
*
* @param ref the {@link ActorRef} of the migrated actor.
* @return the ref
*/
public static <M> ActorRef<M> hire(ActorRef<M> ref) throws SuspendExecution {
return hire(ref, DefaultFiberScheduler.getInstance());
}
/**
* Hires and resumes/restarts a migrated actor.
*
* @param ref the {@link ActorRef} of the migrated actor.
* @param scheduler the {@link FiberScheduler} on which to schedule this actor,
* or {@code null} to schedule the actor on a thread.
* @return the ref
*/
public static <M> ActorRef<M> hire(ActorRef<M> ref, FiberScheduler scheduler) throws SuspendExecution {
Actor actor = MigrationService.hire(ref, Fiber.getFiberSerializer());
@@ -14,9 +14,7 @@
package co.paralleluniverse.actors;
/**
*
* @author pron
* A marker interface that must be implemented by actors wishing to support migration
*/
public interface MigratingActor {
}
@@ -1821,6 +1821,12 @@ private static FlightRecorderMessage makeFlightRecorderMessage(FlightRecorder.Th
}
}
/**
* Parks the fiber and allows the given callback to serialize it.
*
* @param writer a callback that can serialize the fiber.
* @throws SuspendExecution
*/
@SuppressWarnings("empty-statement")
public static void parkAndSerialize(final FiberWriter writer) throws SuspendExecution {
// if (writer == null)
@@ -29,6 +29,7 @@
import java.util.concurrent.TimeoutException;
/**
* A dataflow constant.
* Represents a delayed value that can be set at most once, and when read, blocks until a value has been set.
*
* @author pron
@@ -40,21 +41,21 @@
private volatile SimpleConditionSynchronizer sync = new SimpleConditionSynchronizer(this);
/**
* Creates a {@code DelayedVal} whose value will be the one returned by the given {@link SuspendableCallable}, which will be spawned
* Creates a {@code Val} whose value will be the one returned by the given {@link SuspendableCallable}, which will be spawned
* into a new fiber.
* <p>
* @param f The function that will compute this {@code DelayedVal}'s value in a newly spawned fiber
* @param f The function that will compute this {@code Val}'s value in a newly spawned fiber
*/
public Val(final SuspendableCallable<V> f) {
this(DefaultFiberScheduler.getInstance(), f);
}
/**
* Creates a {@code DelayedVal} whose value will be the one returned by the given {@link SuspendableCallable}, which will be spawned
* Creates a {@code Val} whose value will be the one returned by the given {@link SuspendableCallable}, which will be spawned
* into a new fiber, scheduled by the given {@link FiberScheduler}.
* <p>
* @param scheduler the scheduler in which the new fiber will be spawned.
* @param f The function that will compute this {@code DelayedVal}'s value in a newly spawned fiber
* @param f The function that will compute this {@code Val}'s value in a newly spawned fiber
*/
public Val(FiberScheduler scheduler, final SuspendableCallable<V> f) {
this.f = f;
@@ -31,6 +31,9 @@
import java.util.Set;
/**
* A dataflow variable.
* Represents a variable whose value can be set multiple times and by multiple strands, and whose changing values can be monitored and
* propagated.
*
* @author pron
*/
@@ -61,6 +64,16 @@ public TLVar() {
}
}
/**
* Creates a new {@code Var}, whose value is set to the value returned by the given function {@code f}; the
* function will be re-applied, and the {@code Var}'s value re-set, whenever any of the {@code Var}s referenced
* by {@code f} change value.
*
* @param history how many historical values to maintain for each strand reading the var.
* @param scheduler the {@link FiberScheduler} to use to schedule the fiber that will run, and re-run {@code f}.
* @param f this var's value is set to the return value of {@code f}
* @see #get()
*/
public Var(int history, FiberScheduler scheduler, SuspendableCallable<T> f) {
if (history < 0)
throw new IllegalArgumentException("history must be >= 0, but is " + history);
@@ -71,26 +84,68 @@ public Var(int history, FiberScheduler scheduler, SuspendableCallable<T> f) {
new VarFiber<T>(scheduler != null ? scheduler : DefaultFiberScheduler.getInstance(), this).start();
}
/**
* Creates a new {@code Var}, whose value is set to the value returned by the given function {@code f}; the
* function will be re-applied, and the {@code Var}'s value re-set, whenever any of the {@code Var}s referenced
* by {@code f} change value. The fiber running {@code f} will be scheduled by the default fiber scheduler.
*
* @param history how many historical values to maintain for each strand reading the var.
* @param f this var's value is set to the return value of {@code f}
* @see #get()
*/
public Var(int history, SuspendableCallable<T> f) {
this(history, null, f);
}
/**
* Creates a new {@code Var} with no history, whose value is set to the value returned by the given function {@code f}; the
* function will be re-applied, and the {@code Var}'s value re-set, whenever any of the {@code Var}s referenced
* by {@code f} change value. The fiber running {@code f} will be scheduled by the default fiber scheduler.
*
* @param history how many historical values to maintain for each strand reading the var.
* @param scheduler the {@link FiberScheduler} to use to schedule the fiber that will run, and re-run {@code f}.
* @param f this var's value is set to the return value of {@code f}
* @see #get()
*/
public Var(SuspendableCallable<T> f) {
this(0, null, f);
}
/**
* Creates a new {@code Var} with no history, whose value is set to the value returned by the given function {@code f}; the
* function will be re-applied, and the {@code Var}'s value re-set, whenever any of the {@code Var}s referenced
* by {@code f} change value.
*
* @param scheduler the {@link FiberScheduler} to use to schedule the fiber that will run, and re-run {@code f}.
* @param f this var's value is set to the return value of {@code f}
* @see #get()
*/
public Var(FiberScheduler scheduler, SuspendableCallable<T> f) {
this(0, scheduler, f);
}
/**
* Creates a new {@code Var}.
*
* @param history how many historical values to maintain for each strand reading the var.
* @see #get()
*/
public Var(int history) {
this(history, null, null);
}
/**
* Creates a new {@code Var} with no history.
*/
public Var() {
this(0, null, null);
}
/**
* Sets a new value for this {@code Var}. The Var can be set multiple times and by multiple strands.
*
* @param val the new value.
*/
public void set(T val) {
try {
record("set", "Set %s to %s", this, val);
@@ -107,7 +162,7 @@ private void notifyRegistered() {
}
/**
* This method returns the Var's current value (more precisely: it returns the oldest value in the maintained history that has
* Returns the Var's current value (more precisely: it returns the oldest value in the maintained history that has
* not yet been returned), unless this Var does not yet have a value; only in that case will this method block.
*/
public T get() throws SuspendExecution, InterruptedException {
@@ -147,6 +202,9 @@ else if (t instanceof Error)
}
}
/**
* Blocks until a new value has been set and returns it.
*/
public T getNext() throws SuspendExecution, InterruptedException {
TLVar tl = tlv.get();
final T val;

0 comments on commit 81a175e

Please sign in to comment.