zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316382747


##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+  TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+  instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+  instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+  instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+  instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+  instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+  instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+  instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+  instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+  instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one 
should resize() the storage
+
+  Bundle::Common::activate().dscp(10).cache_control("max-age=259200");

Review Comment:
   The bundles is something I added fairly recently, and are not mentioned in 
the README. It will need to be documented. And yes, they are "chains", the idea 
is that a Bundle can add as much as it wants, and it is responsible for 
validations etc.
   
   The power of the bundles is to make very common tasks really easy to 
activate. This reduces the size of each script. The bundles are a little bit 
less efficient than explicitly writing the callback ("hook"), because the hooks 
are setup and preparared at compile time, whereas bundles are at runtime. So 
there's an indirection / pointer access for the bundles, which doesn't happen 
when you do "raw" callbacks.
   
   You can mix bundles and callbacks as well, the bundles are evaluated first, 
and then the callbacks. Which means, you can override a bundle if needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to