You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/07/01 20:18:43 UTC
[2/2] git commit: updated refs/heads/vmsync to 1f5c672
Added missing file
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1f5c6723
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1f5c6723
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1f5c6723
Branch: refs/heads/vmsync
Commit: 1f5c6723140f2d0379a6caf9f68c7bbc925993c4
Parents: 3cddc36
Author: Alex Huang <al...@gmail.com>
Authored: Mon Jul 1 10:34:44 2013 -0700
Committer: Alex Huang <al...@gmail.com>
Committed: Mon Jul 1 11:19:27 2013 -0700
----------------------------------------------------------------------
.../cloudstack/context/ServerContexts.java | 68 ++++++++++++++++++++
1 file changed, 68 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1f5c6723/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java b/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java
new file mode 100644
index 0000000..ce4079a
--- /dev/null
+++ b/engine/components-api/src/org/apache/cloudstack/context/ServerContexts.java
@@ -0,0 +1,68 @@
+// 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.
+package org.apache.cloudstack.context;
+
+import org.apache.cloudstack.framework.jobs.AsyncJob;
+import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext;
+
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.utils.db.Transaction;
+
+/**
+ * ServerContextInitializer is responsible for properly setting up the
+ * contexts that all of the CloudStack code expects. This includes
+ * - CallContext
+ * - JobContext
+ * - TransactionContext
+ */
+public class ServerContexts {
+ public static void registerUserContext(long userId, long accountId) {
+ Transaction txn = Transaction.open(Thread.currentThread().getName());
+ CallContext context = CallContext.register(userId, accountId, null);
+ context.putContextParameter("Transaction", txn);
+ AsyncJobExecutionContext.registerPseudoExecutionContext(userId, accountId);
+ }
+
+ public static void unregisterUserContext() {
+ CallContext context = CallContext.unregister();
+ AsyncJobExecutionContext.unregister();
+ Transaction txn = (Transaction)context.getContextParameter("Transaction");
+ txn.close(Thread.currentThread().getName());
+ }
+
+ /**
+ * Use this method to initialize the internal background threads.
+ */
+ public static void registerSystemContext() {
+ Transaction txn = Transaction.open(Thread.currentThread().getName());
+ CallContext context = CallContext.registerSystemCallContextOnceOnly();
+ context.putContextParameter("Transaction", txn);
+ AsyncJobExecutionContext.registerPseudoExecutionContext(Account.ACCOUNT_ID_SYSTEM, User.UID_SYSTEM);
+ }
+
+ public static void unregisterSystemContext() {
+ CallContext context = CallContext.unregister();
+ AsyncJobExecutionContext.unregister();
+ Transaction txn = (Transaction)context.getContextParameter("Transaction");
+ txn.close(Thread.currentThread().getName());
+ }
+
+ public static void registerJobContext(long userId, long accountId, AsyncJob job) {
+ CallContext.register(userId, accountId, null);
+ }
+}