Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
first webmachine commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Feb 19, 2011
1 parent 8293f94 commit a1185e4
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 858 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ ebin
doc
.eunit
*~
deps
priv/log
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ APP := monic
.PHONY: deps

all: deps
@(./rebar compile)
@./rebar compile

deps:
@(./rebar get-deps)
@./rebar get-deps

clean:
@(./rebar clean)
@./rebar clean

distclean: clean
@(./rebar delete-deps)

rel: all
@(./rebar generate)
@./rebar delete-deps

docs:
@erl -noshell -run edoc_run application '$(APP)' '"."' '[]'

test: all
@(./rebar skip_deps=true eunit)
35 changes: 35 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Project Skeleton for the monic app.

You should find in this directory:

README : this file
Makefile : simple make commands
rebar : the Rebar build tool for Erlang applications
rebar.config : configuration for Rebar
start.sh : simple startup script for running monic
/ebin
/monic.app : the Erlang app specification
/src
/monic_app.erl : base module for the Erlang application
/monic_sup.erl : OTP supervisor for the application
/monic_resource.erl : a simple example Webmachine resource
/priv
/dispatch.conf : the Webmachine URL-dispatching table
/www : a convenient place to put your static web content

You probably want to do one of a couple of things at this point:

0. Build the skeleton application:
$ make
- or -
$ ./rebar compile

1. Start up the skeleton application:
$ ./start.sh

2. Change the basic application:
edit src/monic_resource.erl

3. Add some new resources:
edit src/YOUR_NEW_RESOURCE.erl
edit priv/dispatch.conf
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

52 changes: 0 additions & 52 deletions TODO

This file was deleted.

20 changes: 0 additions & 20 deletions include/monic.hrl

This file was deleted.

3 changes: 3 additions & 0 deletions priv/dispatch.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%%-*- mode: erlang -*-

{[file], monic_file_manager, []}.
Binary file modified rebar
Binary file not shown.
3 changes: 3 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%%-*- mode: erlang -*-

{deps, [{webmachine, "1.8.*", {git, "git://github.com/basho/webmachine", "HEAD"}}]}.
29 changes: 8 additions & 21 deletions src/monic.app.src
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
% Copyright 2011 Cloudant
%
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.

%%-*- mode: erlang -*-
{application, monic,
[
{description, "Contiguous attachment storage system"},
{vsn, git},
{description, "monic"},
{vsn, "1"},
{modules, []},
{registered, []},
{applications, [
kernel,
stdlib,
crypto
crypto,
mochiweb,
webmachine
]},
{mod, { monic_app, []}},
{env, [
{root_dir,"tmp"},
{concurrency, 10}
]}
{env, []}
]}.
98 changes: 38 additions & 60 deletions src/monic.erl
Original file line number Diff line number Diff line change
@@ -1,67 +1,45 @@
% Copyright 2011 Cloudant
%
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.
%% @author author <author@example.com>
%% @copyright YYYY author.

%% @doc monic startup code

-module(monic).
-export([start/0, stop/0]).
-export([write/2, read/2, read/3, read/4, delete/2]).
-include("monic.hrl").
-author('author <author@example.com>').
-export([start/0, start_link/0, stop/0]).

ensure_started(App) ->
case application:start(App) of
ok ->
ok;
{error, {already_started, App}} ->
ok
end.

%% @spec start_link() -> {ok,Pid::pid()}
%% @doc Starts the app for inclusion in a supervisor tree
start_link() ->
ensure_started(crypto),
ensure_started(mochiweb),
application:set_env(webmachine, webmachine_logger_module,
webmachine_logger),
ensure_started(webmachine),
monic_sup:start_link().

%% @spec start() -> ok
%% @doc Start the monic server.
start() ->
ensure_started(crypto),
ensure_started(mochiweb),
application:set_env(webmachine, webmachine_logger_module,
webmachine_logger),
ensure_started(webmachine),
application:start(monic).

%% @spec stop() -> ok
%% @doc Stop the monic server.
stop() ->
application:stop(monic).

write(Group, Bin) when is_binary(Bin) ->
call(Group, {write, Bin});
write(Group, Fun) when is_function(Fun) ->
call(Group, {write, Fun}).

read(Group, #handle{}=Handle) ->
call(Group, {read, Handle}).

read(Group, #handle{}=Handle, Fun) when is_function(Fun) ->
call(Group, {read, Handle, Fun}).

read(Group, #handle{}=Handle, Ranges, Fun) when is_function(Fun) ->
call(Group, {read, Handle, Ranges, Fun}).

delete(Group, #handle{}=Handle) ->
call(Group, {delete, Handle}).

call(Group, Msg) ->
gen_server:call(group(Group), Msg, infinity).

group(Group) ->
Spec = {
Group,
{gen_server, start_link, [monic_group, [Group], []]},
temporary, 1, worker, [?MODULE]
},
%% relevant parts of couch_rep.erl below.
case supervisor:start_child(monic_sup, Spec) of
{ok, Pid} ->
Pid;
{error, {already_started, Pid}} ->
Pid;
{error, already_present} ->
case supervisor:restart_child(monic_sup, Group) of
{ok, Pid} ->
Pid;
{error, running} ->
{error, {already_started, Pid}} =
supervisor:start_child(monic_sup, Spec),
Pid
end
end.
Res = application:stop(monic),
application:stop(webmachine),
application:stop(mochiweb),
application:stop(crypto),
Res.
31 changes: 11 additions & 20 deletions src/monic_app.erl
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
% Copyright 2011 Cloudant
%
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.
%% @author author <author@example.com>
%% @copyright YYYY author.

%% @doc Callbacks for the monic application.

-module(monic_app).
-author('author <author@example.com>').

-behaviour(application).
-export([start/2,stop/1]).

%% Application callbacks
-export([start/2, stop/1]).

%% ===================================================================
%% Application callbacks
%% ===================================================================

start(_StartType, _StartArgs) ->
%% @spec start(_Type, _StartArgs) -> ServerRet
%% @doc application start callback for monic.
start(_Type, _StartArgs) ->
monic_sup:start_link().

%% @spec stop(_State) -> ServerRet
%% @doc application stop callback for monic.
stop(_State) ->
ok.
54 changes: 0 additions & 54 deletions src/monic_fake_stream.erl

This file was deleted.

Loading

0 comments on commit a1185e4

Please sign in to comment.