atscppapi
1.0.9
C++ wrapper for Apache Traffic Server API
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Enumerations
Enumerator
Macros
src
include
atscppapi
TransactionPlugin.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2013 LinkedIn Corp. All rights reserved.
3
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of the license at
5
* http://www.apache.org/licenses/LICENSE-2.0
6
*
7
* Unless required by applicable law or agreed to in writing, software distributed under the
8
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9
* either express or implied.
10
*
11
*/
12
13
/**
14
* @file TransactionPlugin.h
15
* @author Brian Geffon
16
* @author Manjesh Nilange
17
*
18
* @brief Contains the interface used in creating Transaciton plugins.
19
*/
20
21
#pragma once
22
#ifndef ATSCPPAPI_TRANSACTIONPLUGIN_H_
23
#define ATSCPPAPI_TRANSACTIONPLUGIN_H_
24
25
#include <
atscppapi/Plugin.h
>
26
#include <
atscppapi/Transaction.h
>
27
#include <
atscppapi/shared_ptr.h
>
28
#include <
atscppapi/Mutex.h
>
29
30
namespace
atscppapi {
31
32
namespace
utils {
33
class
internal;
34
}
/* utils */
35
36
/**
37
* @private
38
*/
39
class
TransactionPluginState;
40
41
/**
42
* @brief The interface used when creating a TransactionPlugin.
43
*
44
* A Transaction Plugin is a plugin that will fire only for the specific Transaction it
45
* was bound to. When you create a TransactionPlugin you call the parent constructor with
46
* the associated Transaction and it will become automatically bound. This means that your
47
* TransactionPlugin will automatically be destroyed when the Transaction dies.
48
*
49
* Implications of this are that you can easily add Transaction scoped storage by adding
50
* a member to a TransactionPlugin since the destructor will be called of your TransactionPlugin
51
* any cleanup that needs to happen can happen in your destructor as you normally would.
52
*
53
* You must always be sure to implement the appropriate callback for the type of hook you register.
54
*
55
* \code
56
* // For a more detailed example see examples/transactionhook/
57
* class TransactionHookPlugin : publicTransactionPlugin {
58
* public:
59
* TransactionHookPlugin(Transaction &transaction) : TransactionPlugin(transaction) {
60
* char_ptr_ = new char[100]; // Transaction scoped storage
61
* registerHook(HOOK_SEND_RESPONSE_HEADERS);
62
* }
63
* virtual ~TransactionHookPlugin() {
64
* delete[] char_ptr_; // cleanup
65
* }
66
* void handleSendResponseHeaders(Transaction &transaction) {
67
* transaction.resume();
68
* }
69
* private:
70
* char *char_ptr_;
71
* };
72
* \endcode
73
*
74
* @see Plugin
75
* @see HookType
76
*/
77
class
TransactionPlugin
:
public
Plugin
{
78
public
:
79
/**
80
* registerHook is the mechanism used to attach a transaction hook.
81
*
82
* \note Whenever you register a hook you must have the appropriate callback definied in your TransactionPlugin
83
* see HookType and Plugin for the correspond HookTypes and callback methods. If you fail to implement the
84
* callback, a default implmentation will be used that will only resume the Transaction.
85
*
86
* @param HookType the type of hook you wish to register
87
* @see HookType
88
* @see Plugin
89
*/
90
void
registerHook
(
Plugin::HookType
hook_type);
91
virtual
~
TransactionPlugin
();
92
protected
:
93
TransactionPlugin
(
Transaction
&transaction);
94
95
/**
96
* This method will return a shared_ptr to a Mutex that can be used for AsyncProvider and AsyncReceiver operations.
97
*
98
* If another thread wanted to stop this transaction from dispatching an event it could be passed
99
* this mutex and it would be able to lock it and prevent another thread from dispatching back into this
100
* TransactionPlugin.
101
*/
102
shared_ptr<Mutex>
getMutex
();
103
private
:
104
TransactionPluginState *state_;
/**< The internal state for a TransactionPlugin */
105
friend
class
utils::internal;
106
};
107
108
}
/* atscppapi */
109
110
111
#endif
/* ATSCPPAPI_TRANSACTIONPLUGIN_H_ */
Generated on Mon Oct 14 2013 11:39:29 for atscppapi by
1.8.3.1